diff --git a/app/Filament/Superman/Resources/JamaahResource.php b/app/Filament/Superman/Resources/JamaahResource.php index 858b570..e0747c9 100644 --- a/app/Filament/Superman/Resources/JamaahResource.php +++ b/app/Filament/Superman/Resources/JamaahResource.php @@ -9,6 +9,7 @@ use Filament\Forms\Form; use Filament\Resources\Resource; use Filament\Tables; +use Filament\Tables\Filters; use Filament\Tables\Table; use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\SoftDeletingScope; @@ -19,31 +20,46 @@ class JamaahResource extends Resource protected static ?string $navigationIcon = 'heroicon-o-users'; protected static ?string $navigationLabel = 'Jamaah'; + protected static ?string $pluralLabel = 'Jamaah'; public static function form(Form $form): Form { return $form ->schema([ - // - ]); + Forms\Components\TextInput::make('name')->required(), + Forms\Components\TextInput::make('website') + ->suffix('.jamaah.com') + ->prefixIcon('heroicon-m-globe-alt') + ->required() + ->alphaDash() + ->unique(table: Jamaah::class, column: "website", ignoreRecord: true), + Forms\Components\Select::make("type")->options([ + 'masjid' => 'Masjid', + 'majelis' => 'Majelis', + ]) + ->selectablePlaceholder(false) + ->required() + + ])->columns(1); } public static function table(Table $table): Table { return $table ->columns([ - // + Tables\Columns\TextColumn::make('name'), + Tables\Columns\TextColumn::make('website'), + Tables\Columns\TextColumn::make('type'), ]) ->filters([ - // + Filters\SelectFilter::make('type') + ->options([ + 'masjid' => 'Masjid', + 'majelis' => 'Majelis', + ]) ]) ->actions([ - Tables\Actions\EditAction::make(), - ]) - ->bulkActions([ - Tables\Actions\BulkActionGroup::make([ - Tables\Actions\DeleteBulkAction::make(), - ]), + Tables\Actions\DeleteAction::make(), ]); } diff --git a/app/Filament/Superman/Resources/JamaahResource/Pages/CreateJamaah.php b/app/Filament/Superman/Resources/JamaahResource/Pages/CreateJamaah.php index e1dcd21..966aa6e 100644 --- a/app/Filament/Superman/Resources/JamaahResource/Pages/CreateJamaah.php +++ b/app/Filament/Superman/Resources/JamaahResource/Pages/CreateJamaah.php @@ -9,4 +9,5 @@ class CreateJamaah extends CreateRecord { protected static string $resource = JamaahResource::class; + protected static bool $canCreateAnother = false; } diff --git a/app/Filament/Superman/Resources/UsersResource.php b/app/Filament/Superman/Resources/UsersResource.php index d3c2d06..22178c9 100644 --- a/app/Filament/Superman/Resources/UsersResource.php +++ b/app/Filament/Superman/Resources/UsersResource.php @@ -6,7 +6,6 @@ use App\Filament\Superman\Resources\UsersResource\RelationManagers; use App\Models\User; use Filament\Forms; -use Filament\Forms\Components\Select; use Filament\Forms\Form; use Filament\Resources\Resource; use Filament\Tables; @@ -24,26 +23,27 @@ public static function form(Form $form): Form { return $form ->schema([ - Select::make('roles')->multiple()->relationship('roles', 'name') - ]); + Forms\Components\TextInput::make('name')->required(), + Forms\Components\Select::make('roles') + ->relationship('roles', 'name') + ->selectablePlaceholder(false) + ->required() + ])->columns(1); } public static function table(Table $table): Table { return $table ->columns([ - // + Tables\Columns\TextColumn::make('name'), + Tables\Columns\TextColumn::make('email'), + Tables\Columns\TextColumn::make('created_at')->label("Register date"), ]) ->filters([ // ]) ->actions([ - Tables\Actions\EditAction::make(), - ]) - ->bulkActions([ - Tables\Actions\BulkActionGroup::make([ - Tables\Actions\DeleteBulkAction::make(), - ]), + Tables\Actions\DeleteAction::make(), ]); } diff --git a/app/Filament/Superman/Resources/UsersResource/Pages/CreateUsers.php b/app/Filament/Superman/Resources/UsersResource/Pages/CreateUsers.php index f3aacbf..6167dbd 100644 --- a/app/Filament/Superman/Resources/UsersResource/Pages/CreateUsers.php +++ b/app/Filament/Superman/Resources/UsersResource/Pages/CreateUsers.php @@ -9,4 +9,5 @@ class CreateUsers extends CreateRecord { protected static string $resource = UsersResource::class; + protected static bool $canCreateAnother = false; } diff --git a/app/Http/Middleware/SupermanMiddleware.php b/app/Http/Middleware/SupermanMiddleware.php new file mode 100644 index 0000000..9876bf3 --- /dev/null +++ b/app/Http/Middleware/SupermanMiddleware.php @@ -0,0 +1,21 @@ +is_superman) ? $next($request) : redirect(to: route("filament.jamaah.auth.login")); + } +} diff --git a/app/Http/Middleware/UserMiddleware.php b/app/Http/Middleware/UserMiddleware.php new file mode 100644 index 0000000..7a24568 --- /dev/null +++ b/app/Http/Middleware/UserMiddleware.php @@ -0,0 +1,21 @@ +is_superman) ? redirect(to: route("filament.superman.pages.dashboard")) : $next($request); + } +} diff --git a/app/Models/User.php b/app/Models/User.php index c6c1212..45f6fe0 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -49,19 +49,10 @@ protected function casts(): array return [ 'email_verified_at' => 'datetime', 'password' => 'hashed', + 'is_superman' => 'boolean', ]; } - public function canAccessPanel(Panel $panel): bool - { - // Only Superman can go to Krypton 🫳🫳 - if ($panel->getId() === 'superman') { - return $this->hasRole("superman"); - } - - return true; - } - public function jamaah(): BelongsToMany { return $this->belongsToMany(Jamaah::class); diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index 55122f1..da4572f 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -27,7 +27,7 @@ public function boot(): void Model::unguard(); Gate::before(function (User $user, string $ability) { - return $user->hasRole("superman") ? true : null; + return $user->is_superman ? true : null; }); } } diff --git a/app/Providers/Filament/JamaahPanelProvider.php b/app/Providers/Filament/JamaahPanelProvider.php index 80d8959..f8c99c0 100644 --- a/app/Providers/Filament/JamaahPanelProvider.php +++ b/app/Providers/Filament/JamaahPanelProvider.php @@ -7,6 +7,7 @@ use App\Filament\Jamaah\Pages\Dashboard; use App\Filament\Jamaah\Pages\JamaahProfile; use App\Filament\Jamaah\Pages\JamaahRegistration; +use App\Http\Middleware\UserMiddleware; use App\Models\Jamaah; use DutchCodingCompany\FilamentSocialite\FilamentSocialitePlugin; use DutchCodingCompany\FilamentSocialite\Provider; @@ -69,6 +70,7 @@ public function panel(Panel $panel): Panel SubstituteBindings::class, DisableBladeIconComponents::class, DispatchServingFilamentEvent::class, + UserMiddleware::class ]) ->tenantMiddleware([ SyncSpatiePermissionsWithFilamentTenants::class, diff --git a/app/Providers/Filament/SupermanPanelProvider.php b/app/Providers/Filament/SupermanPanelProvider.php index 4cf3d79..a16432c 100644 --- a/app/Providers/Filament/SupermanPanelProvider.php +++ b/app/Providers/Filament/SupermanPanelProvider.php @@ -5,6 +5,7 @@ use Althinect\FilamentSpatieRolesPermissions\FilamentSpatieRolesPermissionsPlugin; use Althinect\FilamentSpatieRolesPermissions\Middleware\SyncSpatiePermissionsWithFilamentTenants; use App\Filament\Superman\Pages\Dashboard; +use App\Http\Middleware\SupermanMiddleware; use DutchCodingCompany\FilamentSocialite\FilamentSocialitePlugin; use DutchCodingCompany\FilamentSocialite\Provider; use Filament\Http\Middleware\Authenticate; @@ -62,6 +63,7 @@ public function panel(Panel $panel): Panel SubstituteBindings::class, DisableBladeIconComponents::class, DispatchServingFilamentEvent::class, + SupermanMiddleware::class ]) ->authMiddleware([ Authenticate::class, diff --git a/database/migrations/2024_10_27_134847_alter_users_table_add_is_superman_field.php b/database/migrations/2024_10_27_134847_alter_users_table_add_is_superman_field.php new file mode 100644 index 0000000..f1dda35 --- /dev/null +++ b/database/migrations/2024_10_27_134847_alter_users_table_add_is_superman_field.php @@ -0,0 +1,28 @@ +boolean("is_superman")->after("password")->default(false); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('users', function (Blueprint $table) { + $table->dropColumn("is_superman"); + }); + } +}; diff --git a/database/seeders/RoleSeeder.php b/database/seeders/RoleSeeder.php index 8889446..2229f92 100644 --- a/database/seeders/RoleSeeder.php +++ b/database/seeders/RoleSeeder.php @@ -14,19 +14,10 @@ class RoleSeeder extends Seeder */ public function run(): void { - // superman will get special treatment from kripton's Gate - $superman = Role::create( - ['name' => 'superman', "guard_name" => 'web'] - ); - $superman->givePermissionTo( - Permission::where("guard_name", "web")->get() - ); - // Admin Permissions - $admin = Role::create( + Role::create( ['name' => 'admin', "guard_name" => 'web'], ); - // $admin->givePermissionTo( // ['create jamaah', 'unpublish jamaah'] // );