Admin panel and users
The panel
The core registers a Filament 5 panel at /admin. It picks up the site's own Filament classes from these directories, so adding a screen to the admin means adding a class to the site:
app/Filament/Resourcesapp/Filament/Pagesapp/Filament/Widgets
The path is admin_path in config/mela-cms.php.
Changing the panel
To change the panel itself (colours, logo, theme, plugins), extend the core's provider, override panel() starting from what the core sets, and set your class as panel_provider in config/mela-cms.php:
namespace App\Providers\Filament;
use Filament\Panel;
use Filament\Support\Colors\Color;
use Melasistema\MelaCms\Filament\AdminPanelProvider as CoreAdminPanelProvider;
class AdminPanelProvider extends CoreAdminPanelProvider
{
public function panel(Panel $panel): Panel
{
return parent::panel($panel)
->colors(['primary' => Color::Emerald])
->brandLogo(asset('images/logo.svg'));
}
}// config/mela-cms.php
'panel_provider' => \App\Providers\Filament\AdminPanelProvider::class,The core brands the panel: the MelaCMS colours (Mela Blue and Slate grays) and favicon, the MelaCMS mark on the login page, a light, dark and system theme switch in the user menu, and a "Built with MelaCMS" line at the bottom of every page, with the core version for signed-in users. Your own ->colors() and ->favicon() replace the core ones. To remove the mark or the line, return null from loginLogo() or footer() in your class:
protected function footer(): ?\Illuminate\Contracts\View\View
{
return null;
}WARNING
The core registers that class. Do not add it to bootstrap/providers.php, and do not create a second panel with make:filament-panel.
Replacing a core screen
Every screen the core adds is named in the config, so a site can extend it, replace it or remove it:
| Config key | Screen |
|---|---|
resources.pages | Pages |
resources.media | Media library |
resources.users | Users |
pages.settings | Settings |
pages.languages | Languages |
profile_page | Profile |
Set an entry to your own class, which extends the core's, to change the screen. Set it to null to remove it.
Roles
| Role | Access |
|---|---|
super-admin | Passes every authorization check |
admin | Everything an editor does, plus the languages, the settings and the users, except super-admin accounts |
editor | Writes, publishes and deletes pages and the site's own content, and uses the media library. Cannot see the users, languages and settings screens |
The roles are checked in policies. There are no per-role permissions to configure. A site resource without a policy is open to every role; to restrict one, register a policy for its model with Gate::policy().
Roles are provided by spatie/laravel-permission, so the usual methods work on the user model:
use Melasistema\MelaCms\Enums\Role;
$user->assignRole(Role::Editor->value);
$user->hasRole(Role::Admin->value);A user with none of the three roles cannot enter the panel.
The core roles are created after every php artisan migrate, so they exist on a freshly deployed server and in every test that migrates its database.
Users
The core adds a Users screen at /admin/users. Each user has one role.
- Only a super-admin can give the
super-adminrole, or edit and delete a super-admin account. - Nobody can delete their own account or change their own role.
The rules are in Melasistema\MelaCms\Policies\UserPolicy. To change them, register your own policy for the user model in the site's AppServiceProvider:
Gate::policy(User::class, \App\Policies\UserPolicy::class);To add fields, extend the core resource and name your class in the config:
namespace App\Filament\Resources;
use Filament\Forms\Components\TextInput;
use Melasistema\MelaCms\Filament\Resources\Users\UserResource as CoreUserResource;
class UserResource extends CoreUserResource
{
public static function formComponents(): array
{
return [
...parent::formComponents(),
TextInput::make('phone'),
];
}
}// config/mela-cms.php
'resources' => [
'users' => \App\Filament\Resources\UserResource::class,
],tableColumns() works the same way for the list.
Profile
Every user, whatever their role, has a profile page at /admin/profile, reached from the user menu. They can change their name, email and password there. Changing the email or the password asks for the current password.
To add fields, extend Melasistema\MelaCms\Filament\Pages\EditProfile, override form(), and set your class as profile_page in the config.