### Create New Project from Starter Kit (Bash) Source: https://context7.com/ercogx/laravel-filament-starter-kit/llms.txt Installs the Laravel installer globally and creates a new project using the specified starter kit. Navigates into the newly created project directory. ```bash composer global require laravel/installer laravel new my-admin-panel --using=ercogx/laravel-filament-starter-kit cd my-admin-panel ``` -------------------------------- ### Install Laravel Installer Source: https://github.com/ercogx/laravel-filament-starter-kit/blob/main/README.md Installs the Laravel installer globally using Composer, which is a prerequisite for creating new Laravel projects, including those using starter kits. ```bash composer global require laravel/installer ``` -------------------------------- ### Initial Configuration and Database Setup (Bash) Source: https://context7.com/ercogx/laravel-filament-starter-kit/llms.txt Covers essential post-installation steps including optional database configuration (.env file editing for MySQL), running migrations, creating an admin user via Artisan, assigning super admin roles, and generating resource permissions using Filament Shield. ```bash # Configure database (optional - SQLite is default) # Edit .env file for MySQL: # DB_CONNECTION=mysql # DB_HOST=127.0.0.1 # DB_PORT=3306 # DB_DATABASE=my_database # DB_USERNAME=root # DB_PASSWORD=secret # Run migrations (already done in post-install, but for reference) php artisan migrate # Create admin user php artisan make:filament-user # Enter name: Admin User # Enter email: admin@example.com # Enter password: ******** # Assign super admin role to user (user ID 1) php artisan shield:super-admin --user=1 --panel=admin # Generate permissions for all resources php artisan shield:generate --all --ignore-existing-policies --panel=admin ``` -------------------------------- ### Start Development Environment (Bash) Source: https://context7.com/ercogx/laravel-filament-starter-kit/llms.txt Provides commands to start the development server and related services. Includes a shortcut command to run all services concurrently and individual commands for the API server, queue worker, log viewer, and Vite development server. ```bash # Run all services concurrently (API server, queue worker, logs, Vite) composer dev # Or run services individually: php artisan serve # API server on http://localhost:8000 php artisan queue:listen # Queue worker php artisan pail # Log viewer npm run dev # Vite dev server # Access admin panel at http://localhost:8000/admin ``` -------------------------------- ### Create New Project with Starter Kit Source: https://github.com/ercogx/laravel-filament-starter-kit/blob/main/README.md Creates a new Laravel project named 'test-kit' using the 'ercogx/laravel-filament-starter-kit' starter kit. This command automates the setup of a new application with the specified starter kit. ```bash laravel new test-kit --using=ercogx/laravel-filament-starter-kit ``` -------------------------------- ### Write User Resource Feature Tests (PHP) Source: https://context7.com/ercogx/laravel-filament-starter-kit/llms.txt Provides example feature tests for the User resource in a Laravel application. These tests verify that a super admin can view users and that a user without appropriate permissions cannot create new users. It utilizes Laravel's testing utilities like `RefreshDatabase` and `actingAs`. ```php namespace Tests\Feature; use App\Models\User; use Illuminate\Foundation\Testing\RefreshDatabase; use Tests\TestCase; use Spatie\Permission\Models\Role; class UserResourceTest extends TestCase { use RefreshDatabase; public function test_super_admin_can_view_users(): void { $admin = User::factory()->create(); $admin->assignRole('super_admin'); $response = $this->actingAs($admin) ->get('/admin/users'); $response->assertStatus(200); } public function test_user_without_permission_cannot_create_users(): void { $user = User::factory()->create(); $role = Role::create(['name' => 'viewer']); $user->assignRole($role); $response = $this->actingAs($user) ->post('/admin/users', [ 'name' => 'New User', 'email' => 'new@example.com', 'password' => 'password', ]); $response->assertForbidden(); } } ``` -------------------------------- ### Configure User Model with Shield and Roles Traits (PHP) Source: https://context7.com/ercogx/laravel-filament-starter-kit/llms.txt Extends the base User model to integrate with Filament for panel access, Filament Shield for authorization, and Spatie Laravel Permission for role-based access control. It defines fillable and hidden properties, casts for dates and passwords, and implements the `FilamentUser` interface. Usage examples demonstrate checking roles, permissions, and assigning them. ```php // app/Models/User.php namespace App\Models; use BezhanSalleh\FilamentShield\Traits\HasPanelShield; use Filament\Models\Contracts\FilamentUser; use Filament\Panel; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Foundation\Auth\User as Authenticatable; use Illuminate\Notifications\Notifiable; use Spatie\Permission\Traits\HasRoles; class User extends Authenticatable implements FilamentUser { use HasFactory, HasPanelShield, HasRoles, Notifiable; protected $fillable = ['name', 'email', 'password']; protected $hidden = ['password', 'remember_token']; protected $casts = [ 'email_verified_at' => 'datetime', 'password' => 'hashed', ]; // Control panel access via Shield public function canAccessPanel(Panel $panel): bool { return $this->canAccessFilament($panel); } } // Usage: Check user permissions and roles $user = User::find(1); if ($user->hasRole('super_admin')) { // User is super admin } if ($user->can('create_user')) { // User can create users } $user->assignRole('editor'); $user->givePermissionTo('view_any_post'); $user->revokePermissionTo('delete_post'); ``` -------------------------------- ### Configure Panel Plugins and Theme (PHP) Source: https://context7.com/ercogx/laravel-filament-starter-kit/llms.txt Demonstrates how to configure the admin panel in `AdminPanelProvider.php`. This includes setting the panel ID, path, login settings, primary color, discovering resources, pages, and widgets, and registering essential plugins like Filament Shield, Nord Theme, Backgrounds, and Breezy. ```php // app/Providers/Filament/AdminPanelProvider.php use Filament\Panel; use Filament\PanelProvider; use Filament\Support\Colors\Color; use BezhanSalleh\FilamentShield\FilamentShieldPlugin; use Andreia\FilamentNordTheme\FilamentNordThemePlugin; use Swis\Filament\Backgrounds\FilamentBackgroundsPlugin; use Jeffgreco13\FilamentBreezy\BreezyCore; class AdminPanelProvider extends PanelProvider { public function panel(Panel $panel): Panel { return $panel ->default() ->id('admin') ->path('admin') ->login() ->colors([ 'primary' => Color::Amber, // Change primary color ]) ->discoverResources(in: app_path('Filament/Resources'), for: 'App\Filament\Resources') ->discoverPages(in: app_path('Filament/Pages'), for: 'App\Filament\Pages') ->discoverWidgets(in: app_path('Filament/Widgets'), for: 'App\Filament\Widgets') ->plugins([ FilamentShieldPlugin::make(), // Role & permission management FilamentNordThemePlugin::make(), // Nord dark theme FilamentBackgroundsPlugin::make(), // Login page backgrounds BreezyCore::make()->myProfile(), // User profile page ]) ->viteTheme('resources/css/filament/admin/theme.css'); } } ``` -------------------------------- ### Run Code Quality Checks (Bash) Source: https://context7.com/ercogx/laravel-filament-starter-kit/llms.txt Executes various code quality tools including formatters (Pint), test runners (PHPUnit), and static analysis (PHPStan). This command ensures code consistency, correctness, and adherence to standards. Pint formats code, PHPUnit runs tests, and PHPStan detects potential errors. ```bash # Run all checks (Pint, PHPUnit, PHPStan) composer check # Individual checks: ./vendor/bin/pint # Format code ./vendor/bin/pint --dirty # Format only changed files php artisan test # Run PHPUnit tests ./vendor/bin/phpstan analyse --memory-limit=2G # Static analysis # PHPStan configuration (phpstan.neon) # Level 5 analysis is pre-configured for Laravel + Filament ``` -------------------------------- ### Define User Table with Searchable Columns (PHP) Source: https://context7.com/ercogx/laravel-filament-starter-kit/llms.txt Configures a data table for displaying users in Filament. It includes columns for name, email, roles (displayed as badges), and creation timestamp. The table supports searching on name, email, and roles, and allows filtering by roles. It also includes bulk delete actions and an edit action for individual records. Requires `FilamentTables*` components. ```php // app/Filament/Resources/Users/Tables/UsersTable.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\Table; use Filament\Tables\Filters\SelectFilter; class UsersTable { public static function configure(Table $table): Table { return $table ->columns([ TextColumn::make('name') ->searchable() ->sortable(), TextColumn::make('email') ->label('Email address') ->searchable() ->sortable(), TextColumn::make('roles.name') ->badge() ->searchable(), TextColumn::make('created_at') ->dateTime() ->sortable() ->toggleable(isToggledHiddenByDefault: true), ]) ->filters([ SelectFilter::make('roles') ->relationship('roles', 'name') ->multiple() ->preload(), ]) ->recordActions([ EditAction::make(), ]) ->toolbarActions([ BulkActionGroup::make([ DeleteBulkAction::make(), ]), ]); } } ``` -------------------------------- ### Create Filament Admin User Source: https://github.com/ercogx/laravel-filament-starter-kit/blob/main/README.md Generates a new Filament admin user by running the 'make:filament-user' Artisan command. This command is essential for setting up the initial administrator account for the Filament panel. ```bash php artisan make:filament-user ``` -------------------------------- ### Generate Permissions with Shield Source: https://github.com/ercogx/laravel-filament-starter-kit/blob/main/README.md Generates necessary permissions for the 'admin' panel using the 'shield:generate' Artisan command. The `--all` flag generates all possible permissions, and `--ignore-existing-policies` prevents overwriting existing policies. ```bash php artisan shield:generate --all --ignore-existing-policies --panel=admin ``` -------------------------------- ### Run Composer Check Script Source: https://github.com/ercogx/laravel-filament-starter-kit/blob/main/README.md Executes the 'check' script defined in the composer.json file. This script typically runs tests, PHPStan for static analysis, and Pint for code styling, ensuring code quality. ```bash composer check ``` -------------------------------- ### Create User Resource with Role Assignment Source: https://context7.com/ercogx/laravel-filament-starter-kit/llms.txt This PHP code defines a `UserResource` for Filament, which allows for the management of user data. It specifies the model (`User::class`), navigation icon, record title attribute, and navigation group. The resource utilizes separate schema and table configurations (`UserForm` and `UsersTable`) for defining the form fields and table columns, respectively, and sets up routing for listing, creating, and editing users. ```php // app/Filament/Resources/Users/UserResource.php namespace App\Filament\Resources\Users; use App\Filament\Resources\Users\Schemas\UserForm; use App\Filament\Resources\Users\Tables\UsersTable; use App\Models\User; use Filament\Resources\Resource; use Filament\Schemas\Schema; use Filament\Tables\Table; use Filament\Support\Icons\Heroicon; class UserResource extends Resource { protected static ?string $model = User::class; protected static string|BackedEnum|null $navigationIcon = Heroicon::User; protected static ?string $recordTitleAttribute = 'name'; protected static string|UnitEnum|null $navigationGroup = 'Administration'; 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 getPages(): array { return [ 'index' => ListUsers::route('/'), 'create' => CreateUser::route('/create'), 'edit' => EditUser::route('/{record}/edit'), ]; } } ``` -------------------------------- ### Configure Filament Activity Logger Source: https://context7.com/ercogx/laravel-filament-starter-kit/llms.txt This configuration file (`config/filament-logger.php`) allows you to customize the activity logging behavior in your Filament application. You can enable logging for resource CRUD operations, user login/logout activities, Filament notifications, and specific model events. The logs are stored in the `activity_log` table using the Spatie Activity Log package and can be viewed via the Activity Log resource. ```php // config/filament-logger.php return [ 'datetime_format' => 'd/m/Y H:i:s', // Log resource CRUD operations 'resources' => [ 'enabled' => true, 'log_name' => 'Resource', 'navigation_group' => 'Settings', 'exclude' => [ // App\Filament\Resources\SensitiveResource::class, ], ], // Log login/logout activities 'access' => [ 'enabled' => true, 'log_name' => 'Access', 'color' => 'danger', ], // Log Filament notifications 'notifications' => [ 'enabled' => true, 'log_name' => 'Notification', ], // Log specific model events 'models' => [ 'enabled' => true, 'log_name' => 'Model', 'register' => [ App\Models\Order::class, App\Models\Invoice::class, ], ], ]; // View logs at /admin (Activity Log resource in Settings navigation group) // Logs are stored in activity_log table via Spatie Activity Log package ``` -------------------------------- ### Implement User Resource Authorization Policy (PHP) Source: https://context7.com/ercogx/laravel-filament-starter-kit/llms.txt Defines authorization policies for the User resource in Laravel, mapping actions like view, create, update, and delete to specific permissions. This policy class uses Laravel's built-in authorization traits and relies on user permissions being checkable via the `can` method. ```php namespace App\Policies; use Illuminate\Foundation\Auth\User as AuthUser; use Illuminate\Auth\Access\HandlesAuthorization; class UserPolicy { use HandlesAuthorization; public function viewAny(AuthUser $authUser): bool { return $authUser->can('view_any_user'); } public function view(AuthUser $authUser): bool { return $authUser->can('view_user'); } public function create(AuthUser $authUser): bool { return $authUser->can('create_user'); } public function update(AuthUser $authUser): bool { return $authUser->can('update_user'); } public function delete(AuthUser $authUser): bool { return $authUser->can('delete_user'); } public function restore(AuthUser $authUser): bool { return $authUser->can('restore_user'); } public function forceDelete(AuthUser $authUser): bool { return $authUser->can('force_delete_user'); } } // Register policy in AuthServiceProvider (optional if using Shield's auto-discovery) protected $policies = [ User::class => UserPolicy::class, ]; ``` -------------------------------- ### Configure Filament Shield Permissions and Roles Source: https://context7.com/ercogx/laravel-filament-starter-kit/llms.txt This configuration file (`config/filament-shield.php`) allows you to define how Filament Shield handles permissions and roles. It enables features like super admin configuration, custom permission naming conventions, automatic policy generation for resources, and exclusion of specific pages from permission generation. You can also grant permissions to roles programmatically. ```php // config/filament-shield.php return [ 'shield_resource' => [ 'slug' => 'shield/roles', 'show_model_path' => true, ], // Enable super admin with all permissions 'super_admin' => [ 'enabled' => true, 'name' => 'super_admin', 'define_via_gate' => false, ], // Permission naming convention 'permissions' => [ 'separator' => '_', 'case' => 'snake', // Results in: view_any_user, create_user, etc. ], // Auto-generate policies for resources 'policies' => [ 'path' => app_path('Policies'), 'generate' => true, 'methods' => [ 'viewAny', 'view', 'create', 'update', 'delete', 'restore', 'forceDelete', 'forceDeleteAny', 'restoreAny', ], ], // Exclude entities from permission generation 'pages' => [ 'exclude' => [ \Filament\Pages\Dashboard::class, ], ], ]; // Grant permissions to roles php artisan shield:generate --all --panel=admin // Create custom role via UI at /admin/shield/roles // Or programmatically: use Spatie\Permission\Models\Role; use Spatie\Permission\Models\Permission; $role = Role::create(['name' => 'editor']); $role->givePermissionTo(['view_any_user', 'view_user']); ``` -------------------------------- ### Define User Form with Password and Role Fields (PHP) Source: https://context7.com/ercogx/laravel-filament-starter-kit/llms.txt Configures a form schema for user management in Filament, including fields for name, email, password (with confirmation and hashing), and roles. It utilizes Filament's form components and requires the `FilamentSchemasSchema` and `IlluminateSupportFacadesHash` classes. The password field is only required during creation and is hashed using `Hash::make`. ```php // app/Filament/Resources/Users/Schemas/UserForm.php namespace App\Filament\Resources\Users\Schemas; use Filament\Forms\Components\Select; use Filament\Forms\Components\TextInput; use Filament\Schemas\Schema; use Illuminate\Support\Facades\Hash; class UserForm { public static function configure(Schema $schema): Schema { return $schema->components([ TextInput::make('name') ->required(), TextInput::make('email') ->label('Email address') ->email() ->required() ->unique(ignoreRecord: true), TextInput::make('password') ->password() ->confirmed() ->dehydrateStateUsing(fn ($state) => Hash::make($state)) ->dehydrated(fn ($state) => filled($state)) ->required(fn (string $context): bool => $context === 'create'), TextInput::make('password_confirmation') ->password() ->dehydrated(false) ->required(fn (string $context): bool => $context === 'create'), Select::make('roles') ->searchable() ->preload() ->required() ->multiple() ->relationship('roles', 'name') ->label('Roles'), ]); } } ``` -------------------------------- ### Assign Super Admin Role Source: https://github.com/ercogx/laravel-filament-starter-kit/blob/main/README.md Assigns the 'super admin' role to a specified user (user ID 1 in this case) for the 'admin' panel using the 'shield:super-admin' Artisan command. This is part of the user role management provided by the Shield plugin. ```bash php artisan shield:super-admin --user=1 --panel=admin ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.