git add .
git commit "Add admin management search sort and permission structure preparation"
This commit is contained in:
@@ -35,7 +35,7 @@ class AdminGenerator extends Command
|
||||
'mobile' => '09119533286',
|
||||
'password' => Hash::make('hatame14'),
|
||||
'image' => '',
|
||||
'status' => 'active',
|
||||
'status' => 1,
|
||||
]);
|
||||
|
||||
$this->info('hatame created successfully.');
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace App\Enums;
|
||||
|
||||
enum AdminStatus : int
|
||||
{
|
||||
case Inactive=0;
|
||||
case Active=1;
|
||||
case Blocked=2;
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Admin\AdminUpdateRequest;
|
||||
use App\Http\Requests\AdminStoreRequest;
|
||||
use App\Models\Admin;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
|
||||
class AdminController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
$admins=Admin::query()
|
||||
->applySearch()
|
||||
->applySort()
|
||||
->latest()
|
||||
->paginate(2);
|
||||
|
||||
return view('admin.admins.index',compact('admins')) ;
|
||||
}
|
||||
|
||||
public function create()
|
||||
{
|
||||
return view('admin.admins.create');
|
||||
}
|
||||
public function store(AdminStoreRequest $request)
|
||||
{
|
||||
$adminData=$request->validated();
|
||||
$adminData['password']=Hash::make($adminData['password']);
|
||||
|
||||
Admin::create($adminData);
|
||||
|
||||
return redirect()
|
||||
->route('admin.admins.index')
|
||||
->with('success','مدیر جدید با موفقیت اضافه شد.');
|
||||
}
|
||||
|
||||
public function edit(Admin $admin)
|
||||
{
|
||||
return view('admin.admins.edit',compact('admin'));
|
||||
}
|
||||
public function update( AdminUpdateRequest $request,Admin $admin)
|
||||
{
|
||||
$adminData=$request->validated();
|
||||
|
||||
if ($request->filled('password')) {
|
||||
|
||||
$adminData['password'] = Hash::make($adminData['password']);
|
||||
|
||||
} else {
|
||||
|
||||
unset($adminData['password']);
|
||||
|
||||
}
|
||||
|
||||
$admin->update($adminData);
|
||||
|
||||
return redirect()
|
||||
->route('admin.admins.index')
|
||||
->with('success','اطلاعات مدیر با موفقیت ویرایش شد.');
|
||||
|
||||
}
|
||||
|
||||
public function destroy(Admin $admin)
|
||||
{
|
||||
$admin->delete();
|
||||
|
||||
return redirect()->route('admin.admins.index')
|
||||
->with('مدیر با موفقیت حذف شد. ');
|
||||
}
|
||||
}
|
||||
@@ -2,17 +2,37 @@
|
||||
|
||||
namespace App\Http\Controllers\Admin\Auth;
|
||||
|
||||
use App\Enums\AdminStatus;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Requests\Admin\Auth\LoginPostRequest;
|
||||
use App\Models\Admin;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class AuthController extends Controller
|
||||
{
|
||||
public function login()
|
||||
{
|
||||
return view('admin.auth.login');
|
||||
$rawLayout = true;
|
||||
$title='ورود به حساب کاربری';
|
||||
return view('admin.auth.login',compact('rawLayout','title'));
|
||||
}
|
||||
public function loginPost()
|
||||
public function loginPost(LoginPostRequest $request)
|
||||
{
|
||||
$loginData=$request->validated();
|
||||
|
||||
$admins=Admin::query()
|
||||
->where('username',$request->input('username'))
|
||||
->where('status',AdminStatus::Active)
|
||||
->first();
|
||||
|
||||
if (!$admins){
|
||||
return back()->withErrors([
|
||||
'general' => 'اطلاعات وارد شده نامعتبر است'
|
||||
]);
|
||||
}
|
||||
|
||||
Auth::guard('admin')->login($admins);
|
||||
return redirect()->route('admin.dashboard.index');
|
||||
|
||||
}
|
||||
public function logout()
|
||||
|
||||
@@ -3,8 +3,25 @@
|
||||
namespace App\Http\Controllers\Admin\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Admin;
|
||||
use App\Models\Flight;
|
||||
use App\Models\Tour;
|
||||
use App\Models\User;
|
||||
|
||||
class DashboardController extends Controller
|
||||
{
|
||||
//
|
||||
public function index()
|
||||
{
|
||||
$adminsCount = Admin::count();
|
||||
|
||||
$usersCount = User::count();
|
||||
|
||||
$toursCount = Tour::count();
|
||||
|
||||
$flightsCount = Flight::count();
|
||||
|
||||
return view('admin.dashboard',compact('adminsCount',
|
||||
'usersCount','toursCount','flightsCount'
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,16 +10,15 @@ class CommentController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
$withoutHero=true;
|
||||
|
||||
$comments=Comment::query()
|
||||
->where('user_id',auth()->id())
|
||||
->with('tour')
|
||||
->latest()
|
||||
->paginate(4);
|
||||
|
||||
return view('account.users.comments.index', [
|
||||
'comments' => $comments,
|
||||
'withoutHero' => true
|
||||
]);
|
||||
return view('account.users.comments.index',compact('withoutHero','comments'));
|
||||
}
|
||||
|
||||
public function store(CommentStoreRequest $request)
|
||||
|
||||
@@ -9,15 +9,14 @@ class FavoriteController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
$withoutHero=true;
|
||||
|
||||
$favorites = Favorite::with('favoritable')
|
||||
->where('user_id', auth()->id())
|
||||
->latest()
|
||||
->get();
|
||||
|
||||
return view('account.users.favorite.index', [
|
||||
'favorites' => $favorites,
|
||||
'withoutHero' => true
|
||||
]);
|
||||
return view('account.users.favorite.index',compact('withoutHero','favorites'));
|
||||
} public function store(Request $request)
|
||||
{
|
||||
Favorite::firstOrCreate([
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class IndexController extends Controller
|
||||
{
|
||||
//
|
||||
public function index()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Admin;
|
||||
|
||||
use Illuminate\Contracts\Validation\ValidationRule;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class AdminUpdateRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array<string, ValidationRule|array<mixed>|string>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'first_name'=>[
|
||||
'required',
|
||||
'string',
|
||||
'max:50'
|
||||
],
|
||||
'last_name'=>[
|
||||
'required',
|
||||
'string',
|
||||
'max:50'
|
||||
],
|
||||
'username'=>[
|
||||
'required',
|
||||
'string',
|
||||
],
|
||||
'email'=>[
|
||||
'required',
|
||||
'email',
|
||||
],
|
||||
'mobile'=>[
|
||||
'required',
|
||||
],
|
||||
'password'=>[
|
||||
'nullable',
|
||||
'min:8'
|
||||
],
|
||||
'status'=>[
|
||||
'required',
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Admin\Auth;
|
||||
|
||||
use Illuminate\Contracts\Validation\ValidationRule;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class LoginPostRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array<string, ValidationRule|array<mixed>|string>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'username'=>[
|
||||
'required',
|
||||
'string',
|
||||
'min:3',
|
||||
'max:50'
|
||||
],
|
||||
'password'=>[
|
||||
'required',
|
||||
'string',
|
||||
'min:8',
|
||||
'max:255'
|
||||
]
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use Illuminate\Contracts\Validation\ValidationRule;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class AdminStoreRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array<string, ValidationRule|array<mixed>|string>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'first_name'=>[
|
||||
'required',
|
||||
'string',
|
||||
'max:50'
|
||||
],
|
||||
'last_name'=>[
|
||||
'required',
|
||||
'string',
|
||||
'max:50'
|
||||
],
|
||||
'username'=>[
|
||||
'required',
|
||||
'string',
|
||||
'unique:admins,username'
|
||||
],
|
||||
'email'=>[
|
||||
'required',
|
||||
'email',
|
||||
'unique:admins,email'
|
||||
],
|
||||
'mobile'=>[
|
||||
'required',
|
||||
'unique:admins,mobile'
|
||||
],
|
||||
'password'=>[
|
||||
'required',
|
||||
'min:8'
|
||||
],
|
||||
'status'=>[
|
||||
'required',
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
+38
-3
@@ -7,8 +7,9 @@
|
||||
namespace App\Models;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Attributes\Scope;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Foundation\Auth\User;
|
||||
|
||||
|
||||
@@ -54,8 +55,42 @@ class Admin extends User
|
||||
'image',
|
||||
'status'
|
||||
];
|
||||
#[Scope]
|
||||
protected function applySearch(Builder $query): void
|
||||
{
|
||||
$request = request();
|
||||
|
||||
public function roles()
|
||||
if ($request->filled('keyword')) {
|
||||
$keyword = $request->input('keyword');
|
||||
|
||||
$query->whereAny([
|
||||
'first_name',
|
||||
'last_name',
|
||||
], 'LIKE', "%$keyword%");
|
||||
}
|
||||
}
|
||||
|
||||
#[Scope]
|
||||
protected function applySort(Builder $query): void
|
||||
{
|
||||
$sort = request('sort');
|
||||
|
||||
match ($sort) {
|
||||
|
||||
'first_name_asc' =>
|
||||
$query->orderBy('first_name', 'asc'),
|
||||
|
||||
'first_name_desc' =>
|
||||
$query->orderBy('first_name', 'desc'),
|
||||
|
||||
'newest' =>
|
||||
$query->orderBy('created_at', 'desc'),
|
||||
|
||||
default =>
|
||||
$query->orderBy('created_at', 'desc'),
|
||||
|
||||
};
|
||||
} public function roles()
|
||||
{
|
||||
return $this->belongsToMany(Role::class, 'admin_roles');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user