Implementing Role-Based Access Control for Custom Pages on Filament

Hello! How are you? I'm trying to define a specific middleware to access a custom page on Filament. How could I make it so that only, for example, those with the 'teacher' role can access a custom page? Is there a function I can put in page.php?
5 Replies
MK | Programmer
MK | ProgrammerOP8mo ago
I use policies for resources... My page for example
<?php

namespace App\Filament\Pages;

class MySchools extends Page implements HasForms, HasTable
{

use InteractsWithTable;
use InteractsWithForms;

protected static ?string $navigationIcon = 'heroicon-o-academic-cap';

protected static string $view = 'filament.pages.my-schools';

public static ?string $title = 'Minhas Escolas';

public function tableQuery(): \Illuminate\Database\Eloquent\Builder
{

}

public function table(Table $table): Table
{


}
<?php

namespace App\Filament\Pages;

class MySchools extends Page implements HasForms, HasTable
{

use InteractsWithTable;
use InteractsWithForms;

protected static ?string $navigationIcon = 'heroicon-o-academic-cap';

protected static string $view = 'filament.pages.my-schools';

public static ?string $title = 'Minhas Escolas';

public function tableQuery(): \Illuminate\Database\Eloquent\Builder
{

}

public function table(Table $table): Table
{


}
MK | Programmer
MK | ProgrammerOP8mo ago
public static function canAccess(): bool { return auth()->user()->canManageSettings(); } tanks
MK | Programmer
MK | ProgrammerOP8mo ago
Sorry But How do I make it in canAcess for it to go through a middleware coming from App\Http\Middleware?
awcodes
awcodes8mo ago
Have a look at the code for how #bezhansalleh-shield does it. It has page level authorization. Don’t be afraid to source dive. 😁
Want results from more Discord servers?
Add your server