PHP code example of mortalkiller / filament-complete-user-profile

1. Go to this page and download the library: Download mortalkiller/filament-complete-user-profile 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/ */

    

mortalkiller / filament-complete-user-profile example snippets


'storage' => 'separate',

use Mortalkiller\FilamentCompleteUserProfile\CompleteUserProfilePlugin;

public function panel(Panel $panel): Panel
{
    return $panel
        ->plugins([
            CompleteUserProfilePlugin::make(),
        ]);
}

CompleteUserProfilePlugin::make()
    ->overview()
    ->profile()
    ->security()
    ->sessions(false)
    ->apiTokens(false);

use MortalKiller\FilamentPageHeader\PageHeaderPlugin;
use Mortalkiller\FilamentCompleteUserProfile\CompleteUserProfilePlugin;

CompleteUserProfilePlugin::make()
    ->pageHeader(fn (PageHeaderPlugin $header): PageHeaderPlugin => $header->sticky());

use Filament\Support\Enums\Width;

CompleteUserProfilePlugin::make()
    ->maxContentWidth(Width::SixExtraLarge);

use Mortalkiller\FilamentCompleteUserProfile\Features\Security;

CompleteUserProfilePlugin::make()
    ->security(fn (Security $security): Security => $security
        ->appAuthentication());

CompleteUserProfilePlugin::make()
    ->security(fn (Security $security): Security => $security
        ->emailAuthentication());

CompleteUserProfilePlugin::make()
    ->security(fn (Security $security): Security => $security
        ->appAuthentication()
        ->emailAuthentication());

use Mortalkiller\FilamentCompleteUserProfile\Concerns\InteractsWithMultiFactorAuthentication;
use Mortalkiller\FilamentCompleteUserProfile\Contracts\HasMultiFactorAuthentication;

class User extends Authenticatable implements HasMultiFactorAuthentication
{
    use InteractsWithMultiFactorAuthentication;
}

use Filament\Auth\MultiFactor\Email\Contracts\HasEmailAuthentication;
use Illuminate\Notifications\Notifiable;
use Mortalkiller\FilamentCompleteUserProfile\Concerns\InteractsWithEmailAuthentication;

class User extends Authenticatable implements HasEmailAuthentication
{
    use InteractsWithEmailAuthentication;
    use Notifiable;
}

CompleteUserProfilePlugin::make()
    ->sessions();

use Laravel\Sanctum\HasApiTokens;

class User extends Authenticatable
{
    use HasApiTokens;
}

use Mortalkiller\FilamentCompleteUserProfile\Features\ApiTokens;

CompleteUserProfilePlugin::make()
    ->apiTokens(fn (ApiTokens $tokens): ApiTokens => $tokens
        ->abilities([
            'customers:read' => 'Read customers',
            'customers:write' => 'Manage customers',
        ])
        ->defaultExpiration(30)
        ->maxExpiration(90));

CompleteUserProfilePlugin::make()
    ->apiTokens(fn (ApiTokens $tokens): ApiTokens => $tokens
        ->tenantScoped()
        ->abilities([
            'customers:read' => 'Read customers',
        ]));

namespace App\Support\Tenancy;

use Illuminate\Database\Eloquent\Model;
use Mortalkiller\FilamentCompleteUserProfile\Contracts\TenancyResolver;

final class StanclTenancyResolver implements TenancyResolver
{
    public function resolve(): ?Model
    {
        $tenant = tenant();

        return $tenant instanceof Model ? $tenant : null;
    }
}

use App\Support\Tenancy\StanclTenancyResolver;
use Mortalkiller\FilamentCompleteUserProfile\CompleteUserProfilePlugin;
use Mortalkiller\FilamentCompleteUserProfile\Features\ApiTokens;

CompleteUserProfilePlugin::make()
    ->tenancyResolver(StanclTenancyResolver::class)
    ->apiTokens(fn (ApiTokens $tokens): ApiTokens => $tokens
        ->tenantScoped()
        ->abilities([
            'customers:read' => 'Read customers',
        ]));

use Mortalkiller\FilamentCompleteUserProfile\Http\Middleware\EnsureTokenContext;

Route::middleware([
    'auth:sanctum',
    EnsureTokenContext::class,
])->group(function (): void {
    // Tenant-sensitive API routes...
});

use Mortalkiller\FilamentCompleteUserProfile\Features\Profile;

CompleteUserProfilePlugin::make()
    ->profile(fn (Profile $profile): Profile => $profile
        ->locale(['pt', 'en', 'es', 'fr']));

->locale([
    'pt' => 'Português',
    'en' => 'English',
]);

CompleteUserProfilePlugin::make()
    ->profile(fn (Profile $profile): Profile => $profile
        ->avatar(false));

use Filament\Schemas\Components\Component;

CompleteUserProfilePlugin::make()
    ->profile(fn (Profile $profile): Profile => $profile
        ->name(fn (Component $field): Component => $field
            ->helperText('Your public display name.')));

Schema::table('users', function (Blueprint $table): void {
    $table->string('job_title')->nullable();
    $table->string('phone')->nullable();
});

use Filament\Forms\Components\TextInput;

CompleteUserProfilePlugin::make()
    ->profile(fn (Profile $profile): Profile => $profile
        ->fields([
            TextInput::make('job_title')
                ->maxLength(120),
            TextInput::make('phone')
                ->tel()
                ->maxLength(40),
        ]));

use Filament\Schemas\Components\Text;
use Mortalkiller\FilamentCompleteUserProfile\AccountSection;

CompleteUserProfilePlugin::make()
    ->section(
        AccountSection::make('preferences')
            ->label('Preferences')
            ->description('Manage your personal preferences.')
            ->sort(60)
            ->visible(fn (): bool => auth()->user() !== null)
            ->schema([
                Text::make('Preferences content'),
            ]),
    );

use Filament\Actions\Action;
use Filament\Forms\Components\Toggle;
use Filament\Infolists\Components\TextEntry;
use Filament\Schemas\Components\Actions;

AccountSection::make('application-settings')
    ->schema([
        TextEntry::make('weekly_digest')
            ->state(fn (): string => app(DemoSettings::class)->weekly_digest ? 'Enabled' : 'Disabled'),
        Actions::make([
            Action::make('editSettings')
                ->schema([
                    Toggle::make('weekly_digest'),
                ])
                ->fillForm(fn (): array => app(DemoSettings::class)->toArray())
                ->action(function (array $data): void {
                    $settings = app(DemoSettings::class);
                    $settings->weekly_digest = (bool) $data['weekly_digest'];
                    $settings->save();
                }),
        ]),
    ]);

use Filament\Infolists\Components\RepeatableEntry;
use Filament\Infolists\Components\TextEntry;

AccountSection::make('addresses')
    ->schema([
        RepeatableEntry::make('addresses')
            ->state(fn (): array => auth()->user()
                ->addresses()
                ->get(['label', 'line_one', 'city'])
                ->toArray())
            ->schema([
                TextEntry::make('label'),
                TextEntry::make('line_one'),
                TextEntry::make('city'),
            ]),
    ]);

use Filament\Schemas\Components\Livewire;

AccountSection::make('addresses')
    ->schema([
        Livewire::make(\App\Livewire\Account\AddressesTable::class),
    ]);

use Filament\Pages\Page;
use Mortalkiller\FilamentCompleteUserProfile\Concerns\InteractsWithAccountSection;

class Billing extends Page
{
    use InteractsWithAccountSection;

    protected static ?string $slug = 'profile/billing';

    // Define your page content, actions and authorization as usual.
}

CompleteUserProfilePlugin::make()
    ->section(
        AccountSection::make('billing')
            ->label('Billing')
            ->description('Manage your subscription and payment details.')
            ->sort(60)
            ->page(Billing::class),
    );

return [
    'user_model' => null,

    'storage' => 'user',

    'columns' => [
        'avatar' => 'avatar_url',
        'locale' => 'locale',
        'mfa' => [
            'secret' => 'app_authentication_secret',
            'recovery_codes' => 'app_authentication_recovery_codes',
            'email_enabled' => 'has_email_authentication',
        ],
    ],

    'profile_table' => 'filament_user_profiles',
];
bash
php artisan filament:assets
bash
php artisan vendor:publish --tag=filament-complete-user-profile-translations
bash
php artisan migrate
bash
php artisan vendor:publish --tag=filament-complete-user-profile-config
bash
php artisan migrate
bash
php artisan vendor:publish --tag=filament-complete-user-profile-config
bash
php artisan queue:work
bash
php artisan make:session-table
php artisan migrate
bash
composer vendor:publish --provider="Laravel\Sanctum\SanctumServiceProvider"
php artisan migrate
bash
php artisan vendor:publish --tag=filament-complete-user-profile-token-migrations
php artisan migrate
bash
php artisan vendor:publish --tag=filament-complete-user-profile-config
bash
php artisan filament-complete-user-profile:check