F
Filament2mo ago
Mepha

Allow view without view_any

So I have this user with view but without view_any in their role. I want them to be able access
/admin/books/1
/admin/books/1
but not
/admin/books
/admin/books
At BookResource/Pages/ViewBook I've tried adding
public static function canAccess(array $parameters = []): bool
{
return auth()->user()->can('view_book');
}
public static function canAccess(array $parameters = []): bool
{
return auth()->user()->can('view_book');
}
But no luck whatsoever
2 Replies
Dennis Koch
Dennis Koch2mo ago
Try canView() on the resource
Mepha
MephaOP2mo ago
I end up doing this BookResource.php
public static function canAccess(array $parameters = []): bool
{
$user = auth()->user();
return $user->can('view_book') && !$user->can('view_any_book');
}
public static function canAccess(array $parameters = []): bool
{
$user = auth()->user();
return $user->can('view_book') && !$user->can('view_any_book');
}
ViewBook.php
public static function canAccess(array $parameters = []): bool
{
return auth()->user()->can('view_book');
}
public static function canAccess(array $parameters = []): bool
{
return auth()->user()->can('view_book');
}
ListBooks.php
public static function canAccess(array $parameters = []): bool
{
return auth()->user()->can('view_any_book');
}
public static function canAccess(array $parameters = []): bool
{
return auth()->user()->can('view_any_book');
}
Want results from more Discord servers?
Add your server