Easy way to check the current page inside resource class #10042
Replies: 3 comments 5 replies
-
Hi, If you are working from a resource or from a relation manager, why not use Utilities Injections to achieve what you're trying to do, in this case by Injecting the current operation? You then could do something like:
And the result: Check the documentation below, they are really powerful https://filamentphp.com/docs/3.x/forms/advanced#injecting-the-current-form-operation |
Beta Was this translation helpful? Give feedback.
-
I was looking for a way to only show relations on the view page and not on the edit page. I did not find a "Filament" way (maybe there is), but luckily i stumbled on this post. I had to use getRouteName('admin')) because I use multiple panels. So this is my code in the UserResource: use App\Filament\Admin\Resources\UserResource\Pages;
public static function getRelations(): array
{
if (Route::currentRouteName() !== Pages\EditUser::getRouteName('admin')) {
return [
MembershipsRelationManager::class,
];
}
return [];
} I don't think the suggested $operation injection is available here, so I think the the proposed helper function would be a useful addition. |
Beta Was this translation helpful? Give feedback.
-
@danharrin - What do you think about this? It looks like this can be a potentially useful addition, please let me know if we can move forward and start working on the PR (I can work on that). |
Beta Was this translation helpful? Give feedback.
-
Sometimes we have a different behavior when you are in an edit or creating form using a resource, so for that, we need to identify what is the page that is active at the moment.
For example, if we create a Property resource with the following pages:
I want to check if the current page is the
EditProperty
inside thePropertyResource
class I have to do the next:I propose to have a helper method inside
Filament\Resources\Pages\Page
class that is extended for all the pages that check if it's the current page:This is the code that can be inside the
Filament\Resources\Pages\Page
class:This is how to use it:
Example use in real life: In this case, I want to have the
Wizard
component skippable only on the edit page:Beta Was this translation helpful? Give feedback.
All reactions