PHP code example of awcodes / filament-sentry

1. Go to this page and download the library: Download awcodes/filament-sentry 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/ */

    

awcodes / filament-sentry example snippets


use Illuminate\Foundation\Auth\User as Authenticatable;
use BezhanSalleh\FilamentShield\Traits\HasFilamentShield;

class User extends Authenticatable
{
    use HasFilamentShield; // or HasRoles

    // ...
}

    'noreply' => '[email protected]',
    'email_new_users' => true

    'unguard_super_admin' => false,

// CreateUser.php
protected function mutateFormDataBeforeCreate(array $data): array
{
    $nonPermissionsFilter = ['name', 'email', 'password', 'bio', 'etc'];
    ...
}

// EditUser.php
protected function mutateFormDataBeforeSave(array $data): array
{
    $nonPermissionsFilter = ['name', 'email', 'password', 'bio', 'etc'];
    ...
}

use App\Models\User;
use Spatie\Permission\Models\Role;
use Illuminate\Support\Facades\Artisan;
use Spatie\Permission\Models\Permission;

$admin = Role::create(['name' => 'admin'])
    ->givePermissionTo(Permission::where('name', 'not like', '%_role')->get());
$editor = Role::create(['name' => 'editor'])
    ->givePermissionTo(Permission::where('name', 'not like', '%_role')->where('name', 'not like', '%_user')->get());

Artisan::call('shield:generate');

User::withoutEvents(function() {
    User::factory()->create([
        'name' => 'Tony Stark',
        'email' => '[email protected]',
    ])->assignRole('super_admin');

    User::factory()->create([
        'name' => 'Pepper Pots',
        'email' => '[email protected]',
    ])->assignRole('admin');
});
bash
php artisan vendor:publish --tag=filament-sentry-config
bash
php artisan shield:install --fresh
bash
php artisan sentry:eject-resources