I want to use filament as a personal dashboard. Any recommendations on how to go about it?
Hi, I'm new to filamentphp but find it amazing. I was wondering if I can use it to make not a general dashboard but rather a personal one, meaning not to have to choose a user when creating a resource etc as it should be the logged in one. Let's go with the classic to-do example. I want to be able to add tasks for ME as the logged in user. And if a friend create an account they will add to their account, etc etc. How to go about it? Any tips or recommendations of documentations, tutorials, etc?
16 Replies
Create a custom dashboard page https://filamentphp.com/docs/3.x/panels/dashboard#customizing-the-dashboard-page and use the logged in user for anything you need in the view.
Hi, thanks for the quick answer!
Won't it just affect that specific page? Maybe I've phrased myself wrong... This is an example of what I mean:

I wish I didn't have to choose a user there, it should automatically go to me
You donβt have to choose a user, itβs already defined by the laravel auth guard
So, at that point any interaction is defined by the lavavel policy.
you need to modify the form, remove the user select field and instead maybe use a hidden field with auth()->user()->id or add user_id to form data before creation using life cycle hooks.
Use a global Scope to make sure people only see THEIR tasks.
Hmmm okay, I was thinking of something like that as well but was like "what if there's already a standard way to make this happen and I'm missing out?" π
But having u suggest the same makes me think I'm not on the wrong here so that's what I'm gonna go with. Thank you!
You can leave out the User form field and use a Observer or the
creating()
hook for Eloquent models to always prefill the current user id for that model.Depending on the usecase of the models, you can chuck it in the boot function too:
When it is being created and only created, it will assign the authorised users ID.
That's what I meant, but thanks for the code example π
Anytime π
Wow, thank you guys so much for the tips!
Also, now that you've mentioned it, wouldn't this be a good addition to v4? Like having this kind of behavior be enabled with maybe a couple of method calls on the panelProvider or something similar would be pretty neat! Albeit that I have no Idea how complicated would it be to implement π
Itβs already possible. π
@Bruno Gomes so scoping is already part of V4 if you enable it? scopeToTenant = true on the resource. OR scoped to tnenant by default, tenant being users I'd say. But personally? I've just build a trait if you want to apply to a lot:
then add to each model:
wrong @ xD
soz!