PHP code example of joaopaulolndev / filament-edit-profile
1. Go to this page and download the library: Download joaopaulolndev/filament-edit-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/ */
joaopaulolndev / filament-edit-profile example snippets
use Joaopaulolndev\FilamentEditProfile\FilamentEditProfilePlugin;
->plugins([
FilamentEditProfilePlugin::make()
])
use Filament\Actions\Action;
use Joaopaulolndev\FilamentEditProfile\Pages\EditProfilePage;
->userMenuItems([
'profile' => Action::make('profile')
->label(fn() => auth()->user()->name)
->url(fn (): string => EditProfilePage::getUrl())
->icon('heroicon-m-user-circle')
//If you are using tenancy need to check with the visible method where ->company() is the relation between the user and tenancy model as you called
->visible(function (): bool {
return auth()->user()->company()->exists();
}),
])
return [
'disk' => env('FILESYSTEM_DISK', 'public'),
'visibility' => 'public', // or replace by filesystem disk visibility with fallback value
];
protected $fillable = [
'name',
'email',
'password',
'avatar_url', // or column name according to config('filament-edit-profile.avatar_column', 'avatar_url')
];
use Filament\Models\Contracts\HasAvatar;
use Illuminate\Support\Facades\Storage;
class User extends Authenticatable implements HasAvatar
{
// ...
public function getFilamentAvatarUrl(): ?string
{
$avatarColumn = config('filament-edit-profile.avatar_column', 'avatar_url');
return $this->$avatarColumn ? Storage::url($this->$avatarColumn) : null;
}
}
->shouldShowAvatarForm(
value: true,
directory: 'avatars', // image will be stored in 'storage/app/public/avatars
rules: 'mimes:jpeg,png|max:1024' //only accept jpeg and png files with a maximum size of 1MB
)
protected $fillable = [
'name',
'email',
'password',
'locale', // or column name according to config('filament-edit-profile.locale_column', 'locale')
];
->shouldShowThemeColorForm(rules: '
protected $fillable = [
'name',
'email',
'password',
'theme_color', // or column name according to config('filament-edit-profile.theme_color_column', 'theme_color')
];
use Filament\Panel;
use Filament\PanelProvider;
class AdminPanelProvider extends PanelProvider
{
public function panel(Panel $panel): Panel
{
return $panel
// ...
->emailChangeVerification();
}
}
use Laravel\Sanctum\HasApiTokens;
class User extends Authenticatable
{
use HasApiTokens, HasFactory, Notifiable;
}
->plugins([
FilamentEditProfilePlugin::make()
->shouldShowMultiFactorAuthentication(
// The section will only be visible to the user with ID 1.
fn() => auth()->user()->id === 1, //optional
//OR
false //optional
)
])