feat: add user list in admin panel

This commit is contained in:
2026-08-19 15:34:36 +03:30
parent d863e463cb
commit 5fd71b5e85
3 changed files with 314 additions and 0 deletions
@@ -0,0 +1,67 @@
<?php
namespace App\Http\Controllers\Admin;
use App\Http\Controllers\Controller;
use App\Http\Requests\Admins\AdminPostRequest;
use App\Http\Requests\Admins\AdminUserPostRequest;
use App\Models\User;
use Illuminate\Http\Request;
class UserController extends Controller
{
public function index(Request $request)
{
$users = User::query()
->select([
'id',
'first_name',
'last_name',
'mobile',
'email',
'national_code',
'user_province',
'user_city'
])
->when($request->search, function ($query) use ($request) {
$query->whereAny([
'first_name',
'last_name',
'mobile',
'email',
'national_code',
'user_province',
'user_city'
], 'like', '%' . $request->search . '%');
})
->latest()
->paginate(2);
return view('admin.users.user', compact('users'));
}
public function destroy(User $user)
{
$user->delete();
return redirect()
->route('admin.user.index')
->with('success', 'کاربر با موفقیت حذف شد.');
}
public function edit(User $user)
{
return view('admin.users.edit', compact('user'));
}
public function update(AdminUserPostRequest $request, User $user)
{
$inputs = $request->validated();
$user->update($inputs);
return redirect()
->route('admin.user.index')
->with('success', 'اطلاعات کاربر با موفقیت ویرایش شد.');
}
}
@@ -0,0 +1,92 @@
```blade
@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.user.update', $user->id) }}" method="POST">
@csrf
@method('PUT')
<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', $user->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', $user->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="text" name="email" class="form-control"
value="{{ old('email', $user->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="text" name="mobile" class="form-control"
value="{{ old('mobile', $user->mobile) }}" placeholder="موبایل">
@error('mobile')
<span class="text-danger">{{ $message }}</span>
@enderror
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label>استان</label>
<input type="text" name="user_province" class="form-control"
value="{{ old('user_province', $user->user_province) }}" placeholder="استان">
@error('user_province')
<span class="text-danger">{{ $message }}</span>
@enderror
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label>شهر</label>
<input type="text" name="user_city" class="form-control"
value="{{ old('user_city', $user->user_city) }}" placeholder="شهر">
@error('user_city')
<span class="text-danger">{{ $message }}</span>
@enderror
</div>
</div>
</div>
<button type="submit" class="theme-btn mt-4">آپدیت مشخصات کاربر <i class="far fa-user"></i>
</button>
</form>
</div>
</div>
</div>
</div>
@endsection
+155
View File
@@ -0,0 +1,155 @@
@extends('dashboard.layouts.app')
@section('title', 'مدیریت کاربران')
@section('account-content')
<div class="user-profile-wrapper">
<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-right">
<div class="user-profile-search">
<form action="{{ route('admin.user.index') }}" method="GET">
<div class="form-group">
<input type="text"
name="search"
class="form-control"
placeholder="جستجو...">
<button type="submit" style="border: none; background: none;">
<i class="far fa-search"></i>
</button>
</div>
</form>
</div>
</div>
</div>
<div class="col-lg-12">
<div class="table-responsive">
<table class="table text-nowrap">
<thead>
<tr>
<th>نام و نام خانوادگی</th>
<th>شماره موبایل</th>
<th>ایمیل</th>
<th>کد ملی</th>
<th>استان</th>
<th>شهر</th>
</tr>
</thead>
<tbody>
@forelse($users as $user)
<tr>
<td>
<div class="table-listing-info">
<div class="table-listing-content">
<h6>
{{ $user->first_name }}
{{ $user->last_name }}
</h6>
</div>
</div>
</td>
<td>
<h6>
{{ $user->mobile }}
</h6>
</td>
<td>
<h6>
{{ $user->email }}
</h6>
</td>
<td>
<h6>
{{ $user->national_code }}
</h6>
</td>
<td>
@if($user->user_province == null)
<h6>-----</h6>
@else
<h6>
{{ $user->user_province }}
</h6>
@endif
</td>
<td>
@if($user->user_city == null)
<h6>-----</h6>
@else
<h6>
{{ $user->user_city }}
</h6>
@endif
</td>
<td>
<a href="{{ route('admin.user.edit', $user->id) }}"
class="btn btn-outline-secondary btn-sm">
<i class="far fa-pen"></i>
</a>
<form action="{{ route('admin.user.destroy', $user->id) }}"
method="POST"
style="display: inline-block;"
onsubmit="return confirm('آیا از حذف این کاربر مطمئن هستید؟');">
@csrf
@method('DELETE')
<button type="submit" class="btn btn-outline-secondary btn-sm">
<i class="far fa-trash-can"></i>
</button>
</form>
</td>
</tr>
@empty
<tr>
<td colspan="6" class="text-center">
کاربری وجود ندارد.
</td>
</tr>
@endforelse
</tbody>
</table>
</div>
<div class="pagination-area my-3">
<div aria-label="Page navigation example">
{{ $users->links() }}
</div>
</div>
</div>
</div>
</div>
@endsection