PHP code example of jordanpartridge / filament-skeleton

1. Go to this page and download the library: Download jordanpartridge/filament-skeleton library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

jordanpartridge / filament-skeleton example snippets


use App\Models\Base\BaseModel;

class Post extends BaseModel
{
    protected static function booted()
    {
        parent::booted();
        static::registerModelPermissions();
    }
}

// In controllers
if ($post->checkPermission(auth()->user(), 'update')) {
    // Proceed with update
}

// In Blade templates
@can('update', $post)
    <button>Edit Post</button>
@endcan

// In Filament resources
public static function canViewAny(): bool
{
    return auth()->user()->can('view post');
}

class Post extends BaseModel
{
    public static function getStandardPermissions(): array
    {
        return array_merge(parent::getStandardPermissions(), [
            'publish',
            'archive'
        ]);
    }
}

Route::get('/posts/{post}/edit', [PostController::class, 'edit'])
    ->middleware('check.permission:update');

use App\Filament\Resources\PostResource;
use Filament\Resources\Resource;

class PostResource extends Resource
{
    public static function canViewAny(): bool
    {
        return auth()->user()->can('view post');
    }

    public static function canCreate(): bool
    {
        return auth()->user()->can('create post');
    }

    public static function canEdit(Model $record): bool
    {
        return auth()->user()->can('update post');
    }

    public static function canDelete(Model $record): bool
    {
        return auth()->user()->can('delete post');
    }

    // Custom action
    public function publish()
    {
        abort_unless(auth()->user()->can('publish post'), 403);
        // Publication logic
    }
}