feat: add admin panel layout, dashboard, and user management
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
|
||||
use App\Enums\Admin\AdminStatus;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Admin\AuthLoginPostRequest;
|
||||
use App\Models\Admin;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
|
||||
class AuthController extends Controller
|
||||
{
|
||||
public function login()
|
||||
{
|
||||
$rawLayout = true;
|
||||
$title = 'ورود به حساب کاربری';
|
||||
|
||||
return view('admin.login', compact('rawLayout', 'title'));
|
||||
}
|
||||
|
||||
public function loginPost(AuthLoginPostRequest $request)
|
||||
{
|
||||
$admin = Admin::query()
|
||||
->whereUsername($request->input('username'))
|
||||
->whereStatus(AdminStatus::ACTIVE)
|
||||
->first();
|
||||
|
||||
if (!$admin) {
|
||||
return back()->withErrors([
|
||||
'general' => 'اطلاعات وارد شده نامعتبر است.'
|
||||
]);
|
||||
}
|
||||
if (!Hash::check($request->input('password'), $admin->password)) {
|
||||
return back()->withErrors([
|
||||
'general' => 'اطلاعات وارد شده نامعتبر است.'
|
||||
]);
|
||||
}
|
||||
Auth::guard('admin')->login($admin);
|
||||
|
||||
$admin->update([
|
||||
'last_login_at' => now(),
|
||||
]);
|
||||
|
||||
return redirect()->route('admin.dashboard.index');
|
||||
}
|
||||
|
||||
public function logout()
|
||||
{
|
||||
Auth::guard('admin')->logout();
|
||||
|
||||
return redirect()->route('admin.auth.login.index');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Enums\OrderStatus;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Flight;
|
||||
use App\Models\Order;
|
||||
use App\Models\Product;
|
||||
use App\Models\ProductCategory;
|
||||
use App\Models\Tour;
|
||||
use App\Models\User;
|
||||
use Carbon\Carbon;
|
||||
use Carbon\CarbonPeriod;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class DashboardController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
|
||||
$title = 'داشبورد';
|
||||
$tourCount = Tour::count();
|
||||
$flightCount = Flight::count();
|
||||
|
||||
$userCount = User::count();
|
||||
|
||||
return view('admin.dashboard', compact(
|
||||
'title',
|
||||
'tourCount',
|
||||
'flightCount',
|
||||
'userCount'
|
||||
));
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Flight;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class BookingController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
|
||||
}
|
||||
public function store(Flight $flight)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Admin;
|
||||
|
||||
use Illuminate\Contracts\Validation\ValidationRule;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class AuthLoginPostRequest 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',
|
||||
'alpha_num',
|
||||
'min:2',
|
||||
'max:64'
|
||||
],
|
||||
'password' => [
|
||||
'required',
|
||||
'string',
|
||||
'min:8',
|
||||
'max:150'
|
||||
]
|
||||
];
|
||||
|
||||
}
|
||||
}
|
||||
@@ -8,12 +8,12 @@ namespace App\Models;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Illuminate\Foundation\Auth\User;
|
||||
|
||||
/**
|
||||
* Class Admin
|
||||
*
|
||||
*
|
||||
* @property int $id
|
||||
* @property string $first_name
|
||||
* @property string $last_name
|
||||
@@ -28,13 +28,13 @@ use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
* @property Carbon $created_at
|
||||
* @property Carbon $updated_at
|
||||
* @property string|null $deleted_at
|
||||
*
|
||||
*
|
||||
* @property File|null $file
|
||||
* @property Collection|Comment[] $comments
|
||||
*
|
||||
* @package App\Models
|
||||
*/
|
||||
class Admin extends Model
|
||||
class Admin extends User
|
||||
{
|
||||
use SoftDeletes;
|
||||
protected $table = 'admins';
|
||||
|
||||
Reference in New Issue
Block a user