feat: add create a new admin for admin panel
This commit is contained in:
@@ -5,8 +5,10 @@ namespace App\Http\Controllers\Admin;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Admins\AdminEditPostRequest;
|
||||
use App\Http\Requests\Admins\AdminPostRequest;
|
||||
use App\Http\Requests\Admins\AdminStorePostRequest;
|
||||
use App\Models\Admin;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
|
||||
class AdminController extends Controller
|
||||
{
|
||||
@@ -45,6 +47,23 @@ class AdminController extends Controller
|
||||
->route('admin.admins.index')
|
||||
->with('success', 'اطلاعات مدیر با موفقیت ویرایش شد.');
|
||||
}
|
||||
public function create()
|
||||
{
|
||||
return view('admin.admins.create');
|
||||
}
|
||||
|
||||
public function store(AdminStorePostRequest $request)
|
||||
{
|
||||
$data = $request->validated();
|
||||
|
||||
$data['password'] = Hash::make($data['password']);
|
||||
|
||||
Admin::create($data);
|
||||
|
||||
return redirect()
|
||||
->route('admin.admins.index')
|
||||
->with('success', 'ادمین جدید با موفقیت ثبت شد.');
|
||||
}
|
||||
public function destroy(Admin $admin)
|
||||
{
|
||||
$admin->delete();
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Admins;
|
||||
|
||||
use Illuminate\Contracts\Validation\ValidationRule;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class AdminStorePostRequest 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:255'
|
||||
],
|
||||
'last_name' => [
|
||||
'required',
|
||||
'string',
|
||||
'max:255'
|
||||
],
|
||||
'email' => [
|
||||
'required',
|
||||
'email',
|
||||
'max:255',
|
||||
'unique:admins,email'
|
||||
],
|
||||
'password' => [
|
||||
'required',
|
||||
'string',
|
||||
'min:8',
|
||||
'confirmed'
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
@extends('dashboard.layouts.app')
|
||||
|
||||
@section('title', 'ثبت ادمین جدید')
|
||||
|
||||
@section('account-content')
|
||||
|
||||
<div class="user-profile-wrapper">
|
||||
|
||||
@if (session('success'))
|
||||
<div class="col-lg-12 mb-3">
|
||||
<div class="alert alert-success">
|
||||
{{ session('success') }}
|
||||
</div>
|
||||
</div>
|
||||
@endif
|
||||
|
||||
<div class="col-lg-12 mb-4">
|
||||
<div class="user-profile-card">
|
||||
|
||||
<h4 class="user-profile-card-title">
|
||||
ثبت ادمین جدید
|
||||
</h4>
|
||||
|
||||
<div class="user-profile-form">
|
||||
|
||||
<form action="{{ route('admin.admins.store') }}" method="POST">
|
||||
|
||||
@csrf
|
||||
|
||||
<div class="row">
|
||||
|
||||
<div class="col-md-6">
|
||||
<div class="form-group">
|
||||
<label>نام</label>
|
||||
<input
|
||||
type="text" name="first_name" class="form-control"
|
||||
value="{{ old('first_name') }}" placeholder="نام"
|
||||
>
|
||||
@error('first_name')
|
||||
<span class="text-danger">{{ $message }}</span>
|
||||
@enderror
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-md-6">
|
||||
<div class="form-group">
|
||||
<label>نام خانوادگی</label>
|
||||
<input
|
||||
type="text" name="last_name" class="form-control"
|
||||
value="{{ old('last_name') }}" placeholder="نام خانوادگی"
|
||||
>
|
||||
@error('last_name')
|
||||
<span class="text-danger">{{ $message }}</span>
|
||||
@enderror
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-md-6">
|
||||
<div class="form-group">
|
||||
<label>ایمیل</label>
|
||||
<input
|
||||
type="email" name="email" class="form-control"
|
||||
value="{{ old('email') }}" placeholder="ایمیل"
|
||||
>
|
||||
@error('email')
|
||||
<span class="text-danger">{{ $message }}</span>
|
||||
@enderror
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-md-6">
|
||||
<div class="form-group">
|
||||
<label>رمز عبور</label>
|
||||
<input
|
||||
type="password" name="password" class="form-control"
|
||||
placeholder="رمز عبور"
|
||||
>
|
||||
@error('password')
|
||||
<span class="text-danger">{{ $message }}</span>
|
||||
@enderror
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-md-6">
|
||||
<div class="form-group">
|
||||
<label>تکرار رمز عبور</label>
|
||||
<input
|
||||
type="password" name="password_confirmation" class="form-control"
|
||||
placeholder="تکرار رمز عبور"
|
||||
>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<button type="submit" class="theme-btn mt-4">
|
||||
ثبت ادمین
|
||||
<i class="far fa-user-plus"></i>
|
||||
</button>
|
||||
|
||||
</form>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
@endsection
|
||||
@@ -78,38 +78,7 @@
|
||||
</button>
|
||||
|
||||
</form>
|
||||
<div class="col-lg-12">
|
||||
<div class="user-profile-card">
|
||||
<h4 class="user-profile-card-title">عوض کردن رمز عبور</h4>
|
||||
<div class="col-lg-12">
|
||||
<div class="user-profile-form">
|
||||
<form action="{{ route('setting.password.update') }}" method="POST">
|
||||
@csrf
|
||||
@method('PUT')
|
||||
<div class="form-group">
|
||||
<label>رمز عبور فعلی</label>
|
||||
<input type="password" name="current_password" class="form-control"
|
||||
placeholder="رمز عبور فعلی">
|
||||
@error('current_password') <span class="text-danger">{{ $message }}</span> @enderror
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>رمز عبور جدید</label>
|
||||
<input type="password" name="new_password" class="form-control"
|
||||
placeholder="رمز عبور جدید">
|
||||
@error('new_password') <span class="text-danger">{{ $message }}</span> @enderror
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>تکرار رمز عبور جدید</label>
|
||||
<input type="password" name="new_password_confirmation" class="form-control"
|
||||
placeholder="تکرار رمز عبور جدید">
|
||||
</div>
|
||||
<button type="submit" class="theme-btn mt-4">عوض کردن رمز عبور <i class="far fa-key"></i>
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -13,24 +13,35 @@
|
||||
@endif
|
||||
|
||||
<div class="user-profile-card user-profile-listing">
|
||||
<div class="user-profile-card-header">
|
||||
<h4 class="user-profile-card-title">لیست مدیران سایت</h4>
|
||||
<div class="user-profile-card-header"
|
||||
style="display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 15px; margin-bottom: 20px;">
|
||||
|
||||
<h4 class="user-profile-card-title" style="margin: 0;">
|
||||
لیست مدیران سایت
|
||||
</h4>
|
||||
|
||||
<div style="display: flex; flex-wrap: wrap; align-items: center; gap: 12px;">
|
||||
|
||||
<div class="user-profile-card-header-right">
|
||||
<div class="user-profile-search">
|
||||
<form action="{{ route('admin.admins.index') }}" method="GET">
|
||||
<div class="form-group">
|
||||
<div style="position: relative; display: inline-block;">
|
||||
<input type="text"
|
||||
name="search"
|
||||
class="form-control"
|
||||
value="{{ request('search') }}"
|
||||
placeholder="جستجو...">
|
||||
<button type="submit" style="border: none; background: none;">
|
||||
<i class="far fa-search"></i>
|
||||
</button>
|
||||
placeholder="جستجو..."
|
||||
style="padding-right: 40px; position: relative;">
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<a href="{{ route('admin.admins.create') }}"
|
||||
class="theme-btn"
|
||||
style="white-space: nowrap; display: inline-flex; align-items: center; gap: 8px;">
|
||||
<i class="far fa-user-plus"></i>
|
||||
ادمین جدید
|
||||
</a>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -29,6 +29,8 @@ Route::prefix('admin')->name('admin.')->group(function () {
|
||||
Route::prefix('admins')->controller(AdminController::class)->name('admins.')->group(function () {
|
||||
|
||||
Route::get('/', 'index')->name('index');
|
||||
Route::get('create', 'create')->name('create');
|
||||
Route::post('/', 'store')->name('store');
|
||||
Route::get('{admin}/edit', 'edit')->name('edit');
|
||||
Route::put('{admin}', 'update')->name('update');
|
||||
Route::delete('{admin}', 'destroy')->name('destroy');
|
||||
|
||||
Reference in New Issue
Block a user