PHP code example of byjesper / laravel-decision-support-filament

1. Go to this page and download the library: Download byjesper/laravel-decision-support-filament 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/ */

    

byjesper / laravel-decision-support-filament example snippets


use ByJesper\DecisionSupportFilament\DecisionSupportPlugin;
use Filament\Panel;

public function panel(Panel $panel): Panel
{
    return $panel
        // ...
        ->plugin(DecisionSupportPlugin::make());
}

use ByJesper\DecisionSupport\DecisionSupportManager;

app(DecisionSupportManager::class)
    ->registerProvider('employment-eligibility', EmploymentFactProvider::class);

use ByJesper\DecisionSupportFilament\Pages\GuideRunner;

class EmploymentGuideRunner extends GuideRunner
{
    protected static ?string $guideKey = 'employment-eligibility'; // pins the guide
    protected static bool $shouldRegisterNavigation = true;
    protected static string | \UnitEnum | null $navigationGroup = 'HR';
    protected static string | \BackedEnum | null $navigationIcon = 'heroicon-o-identification';

    public static function canAccess(): bool
    {
        return auth()->user()?->can('run employment guide') ?? false;
    }
}

// config/decision-support-filament.php
return [
    // Where the GuideResource appears in the panel navigation.
    'navigation' => [
        'group' => 'Decision Support',          // null to ungroup
        'sort' => null,                          // int to order within the group
        'icon' => 'heroicon-o-rectangle-group', // any registered icon
        'label' => null,                         // null => "Guides"; string or translation key
    ],

    // Override the singular/plural model labels (titles, breadcrumbs, buttons).
    // null => Filament's defaults. Strings may be plain text or translation keys.
    'labels' => [
        'model' => null,                         // e.g. 'Decision guide'
        'plural' => null,                        // e.g. 'Decision guides'
    ],

    // How a guide is CREATED from the list: 'page' (default), 'modal', or
    // 'slideover'. Editing always stays a full page — it hosts the versions.
    'forms' => [
        'layout' => 'page',
    ],

    // The catalog of permissions an author can pick from (chosen ones stored on
    // the guide at extra_attributes.permissions):
    //   null      => no catalog; the field becomes a warning callout (you can't
    //                gate by permission until you supply one),
    //   array     => a searchable multi-select with that catalog for every guide,
    //   closure   => fn (?Guide $guide): array, resolved per guide so different
    //                guides offer different catalogs.
    // 'mode' is the default for how the chosen permissions combine — 'any' (OR)
    // or 'all' (AND); authors override it per guide (extra_attributes.permissions_mode).
    'permissions' => [
        'options' => null,
        'mode' => 'any',
    ],

    // The guide list table.
    //   scope_to_viewable    => when true (default), the list shows only guides
    //                           the user can view() per your Guide policy, so each
    //                           guide's 

public function view(User $user, Guide $guide): bool
{
    $]
        ?? config('decision-support-filament.permissions.mode', 'any');

    $held = collect($

use Illuminate\Contracts\Auth\Authenticatable;
use Illuminate\Database\Eloquent\Builder;

$panel->plugin(
    DecisionSupportPlugin::make()->scopeGuideListUsing(
        fn (Builder $query, Authenticatable $user): Builder => $query
            ->whereJsonContains('extra_attributes->permissions', $user->guidePermissions()),
    ),
);

'list' => [
    'reader_hidden_columns' => ['profile', 'versions_count', 'active_version_id'],
],

use ByJesper\DecisionSupport\Models\Guide;
use Illuminate\Support\Facades\Gate;

Gate::policy(Guide::class, GuidePolicy::class);
bash
php artisan vendor:publish --tag=decision-support-filament-config
bash
php artisan vendor:publish --tag=decision-support-filament-translations
bash
php artisan vendor:publish --tag=decision-support-filament-views
bash
php artisan filament:assets
php artisan view:clear
php artisan cache:clear