Laravel Filament
Software Engineer and Mentor!
Setup Project
# create laravel project
composer create-project laravel/laravel learn-filament
# setup env db and migrate
php artisan migrate
# try serve
php artisan server
# open folder
cd learn-filament
# install filament
composer require filament/filament
# install filament on project
php artisan filament:install --panels
# create user
php artisan make:filament-user
# open filament on /admin
http://localhost:8000/admin
Model & Migration
Office Model
php artisan make:model Office -m
Schema::create('offices', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->integer('radius');
$table->double('latitude');
$table->double('longitude');
$table->timestamps();
$table->softDeletes();
});
Shift Model
php artisan make:model Shift -m
Schema::create('shifts', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->time('start_time');
$table->time('end_time');
$table->timestamps();
$table->softDeletes();
});
Schedule Model
php artisan make:model Schedule -m
Schema::create('schedules', function (Blueprint $table) {
$table->id();
$table->foreignId('user_id')->unique()->constrained('users')->cascadeOnDelete();
$table->foreignId('shift_id')->constrained('shifts')->cascadeOnDelete();
$table->foreignId('office_id')->constrained('offices')->cascadeOnDelete();
$table->timestamps();
});
Attendece Model
php artisan make:model Attendece -m
Schema::create('attendeces', function (Blueprint $table) {
$table->id();
$table->foreignId('user_id')->constrained('users')->cascadeOnDelete();
$table->double('schedule_latitude');
$table->double('schedule_longitude');
$table->time('schedule_start_time');
$table->time('schedule_end_time');
$table->double('latitude');
$table->double('longitude');
$table->time('start_time');
$table->time('end_time');
$table->timestamps();
$table->softDeletes();
});
Filement Resources
Shit Resource
php artisan make:filament-resource Shift
Model Relation
class Schedule extends Model
{
protected $guarded = [];
public function user(): BelongsTo {
return $this->belongsTo(User::class);
}
public function shift(): BelongsTo {
return $this->belongsTo(Shift::class);
}
public function office(): BelongsTo {
return $this->belongsTo(Office::class);
}
}
Add Role
composer require bezhansalleh/filament-shield
use Spatie\Permission\Traits\HasRoles;
class User extends Authenticatable
{
use HasRoles;
}
php artisan vendor:publish --tag="filament-shield-config"
php artisan shield:setup
# or if already install
php artisan shield:install admin
# app/Providers/Filament/AdminPanelProvider.php
use BezhanSalleh\FilamentShield\FilamentShieldPlugin;
public function panel(Panel $panel): Panel
{
return $panel
// ...
->plugins([
FilamentShieldPlugin::make(),
]);
}
# add User Form Role
# app/Filament/Resources/Users/Schemas/UserForm.php
Select::make('roles')
->relationship('roles', 'name')
->multiple()
->preload()
->required(),
# show table roles
# app/Filament/Resources/Users/Tables/UsersTable.php
TextColumn::make('roles')
->label('Roles'),
