Auth::id();, Filament::auth()->id();, not working on function booted()
Good day. I encountered an error / bug, i cannot get the current id of logged user
current code: https://pastebin.com/wg7W8g8w
log file:
Pastebin
public static function booted() { // $userId = Auth::...
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
12 Replies
What exactly are you trying to do?
get the current 'id' of current logged user, on booted() function of Checklist.php model
Right but why are you doing an auth check on the booted of a model?
It might be too early in the lifecycle of the app.
to write data on database, on load of the website
That shouldn’t be on the model though.
That should be in a service provider.
oh okay, can you recommend, so what is better way for that
I don’t know because I’m not sure what you are actually trying to do.
What do you need to logged in ID for?
What is the end goal?
I could be completely wrong but it sounds likes you need either a middleware or an observer.
my end goal is 'write a data on database' on load/refresh of the website
so i need the id of the user, so it can be stored on user_id column
Ok, but you’re trying to do that too early in the lifecycle.
so what is the best way to do that sir, if you have any idea
With a middleware.
It’s a laravel concept and not a filament concept.
oh okay okay. lemee try that. thank you.
ANSWER AS OF 071224
on you ManageRecords file of your model (e.g: ManageRequirementsChecklists.php), paste this code: