feat(User,Role): add users and role , permssion , filament panel | [USER , ROLE]

This commit is contained in:
2026-05-29 15:28:56 +03:30
parent d923019dc5
commit 1c408130d0
71 changed files with 3111 additions and 11 deletions

View File

@@ -0,0 +1,11 @@
<?php
namespace App\Filament\Resources\Users\Pages;
use App\Filament\Resources\Users\UserResource;
use Filament\Resources\Pages\CreateRecord;
class CreateUser extends CreateRecord
{
protected static string $resource = UserResource::class;
}

View File

@@ -0,0 +1,19 @@
<?php
namespace App\Filament\Resources\Users\Pages;
use App\Filament\Resources\Users\UserResource;
use Filament\Actions\DeleteAction;
use Filament\Resources\Pages\EditRecord;
class EditUser extends EditRecord
{
protected static string $resource = UserResource::class;
protected function getHeaderActions(): array
{
return [
DeleteAction::make(),
];
}
}

View File

@@ -0,0 +1,19 @@
<?php
namespace App\Filament\Resources\Users\Pages;
use App\Filament\Resources\Users\UserResource;
use Filament\Actions\CreateAction;
use Filament\Resources\Pages\ListRecords;
class ListUsers extends ListRecords
{
protected static string $resource = UserResource::class;
protected function getHeaderActions(): array
{
return [
CreateAction::make(),
];
}
}

View File

@@ -0,0 +1,46 @@
<?php
namespace App\Filament\Resources\Users\Schemas;
use Filament\Forms\Components\CheckboxList;
use Filament\Forms\Components\TextInput;
use Filament\Schemas\Schema;
class UserForm
{
public static function configure(Schema $schema): Schema
{
return $schema
->components([
TextInput::make('name')
->label('نام')
->required()
->maxLength(255),
TextInput::make('email')
->label('ایمیل')
->email()
->required()
->unique(ignoreRecord: true)
->maxLength(255),
TextInput::make('mobile')
->label('شماره موبایل')
->tel()
->unique(ignoreRecord: true)
->maxLength(20),
TextInput::make('password')
->label('رمز عبور')
->password()
->revealable()
->autocomplete('new-password')
->required(fn (string $operation): bool => $operation === 'create')
->saved(fn (?string $state): bool => filled($state))
->maxLength(255),
CheckboxList::make('roles')
->label('نقش‌ها')
->relationship(titleAttribute: 'name')
->searchable()
->bulkToggleable()
->columns(2),
]);
}
}

View File

@@ -0,0 +1,56 @@
<?php
namespace App\Filament\Resources\Users\Tables;
use Filament\Actions\BulkActionGroup;
use Filament\Actions\DeleteBulkAction;
use Filament\Actions\EditAction;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Filters\SelectFilter;
use Filament\Tables\Table;
class UsersTable
{
public static function configure(Table $table): Table
{
return $table
->columns([
TextColumn::make('name')
->label('نام')
->searchable()
->sortable(),
TextColumn::make('email')
->label('ایمیل')
->searchable()
->sortable(),
TextColumn::make('mobile')
->label('شماره موبایل')
->searchable()
->sortable(),
TextColumn::make('roles.name')
->label('نقش‌ها')
->badge()
->searchable(),
TextColumn::make('created_at')
->label('تاریخ ایجاد')
->dateTime()
->sortable()
->toggleable(isToggledHiddenByDefault: true),
])
->filters([
SelectFilter::make('roles')
->label('نقش')
->relationship('roles', 'name')
->searchable()
->preload(),
])
->recordActions([
EditAction::make(),
])
->toolbarActions([
BulkActionGroup::make([
DeleteBulkAction::make(),
]),
]);
}
}

View File

@@ -0,0 +1,58 @@
<?php
namespace App\Filament\Resources\Users;
use App\Filament\Resources\Users\Pages\CreateUser;
use App\Filament\Resources\Users\Pages\EditUser;
use App\Filament\Resources\Users\Pages\ListUsers;
use App\Filament\Resources\Users\Schemas\UserForm;
use App\Filament\Resources\Users\Tables\UsersTable;
use App\Models\User;
use BackedEnum;
use Filament\Resources\Resource;
use Filament\Schemas\Schema;
use Filament\Support\Icons\Heroicon;
use Filament\Tables\Table;
class UserResource extends Resource
{
protected static ?string $model = User::class;
protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedUsers;
protected static ?string $recordTitleAttribute = 'name';
protected static ?string $modelLabel = 'کاربر';
protected static ?string $pluralModelLabel = 'کاربران';
protected static ?string $navigationLabel = 'کاربران';
protected static ?int $navigationSort = 1;
public static function form(Schema $schema): Schema
{
return UserForm::configure($schema);
}
public static function table(Table $table): Table
{
return UsersTable::configure($table);
}
public static function getRelations(): array
{
return [
//
];
}
public static function getPages(): array
{
return [
'index' => ListUsers::route('/'),
'create' => CreateUser::route('/create'),
'edit' => EditUser::route('/{record}/edit'),
];
}
}