Skip to content

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/Resources
  • app/Filament/Pages
  • app/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:

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'));
    }
}
php
// 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:

php
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 keyScreen
resources.pagesPages
resources.mediaMedia library
resources.usersUsers
pages.settingsSettings
pages.languagesLanguages
profile_pageProfile

Set an entry to your own class, which extends the core's, to change the screen. Set it to null to remove it.

Roles ​

RoleAccess
super-adminPasses every authorization check
adminEverything an editor does, plus the languages, the settings and the users, except super-admin accounts
editorWrites, 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:

php
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-admin role, 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:

php
Gate::policy(User::class, \App\Policies\UserPolicy::class);

To add fields, extend the core resource and name your class in the config:

php
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'),
        ];
    }
}
php
// 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.

Code released under the MIT License. The MelaCMS name and logo are trademarks, see Brand.