F
Filament4mo ago
EMMAN

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.
No description
12 Replies
awcodes
awcodes4mo ago
What exactly are you trying to do?
EMMAN
EMMAN4mo ago
get the current 'id' of current logged user, on booted() function of Checklist.php model
awcodes
awcodes4mo ago
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.
EMMAN
EMMAN4mo ago
to write data on database, on load of the website
awcodes
awcodes4mo ago
That shouldn’t be on the model though. That should be in a service provider.
EMMAN
EMMAN4mo ago
oh okay, can you recommend, so what is better way for that
awcodes
awcodes4mo ago
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.
EMMAN
EMMAN4mo ago
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
awcodes
awcodes4mo ago
Ok, but you’re trying to do that too early in the lifecycle.
EMMAN
EMMAN4mo ago
so what is the best way to do that sir, if you have any idea
awcodes
awcodes4mo ago
With a middleware. It’s a laravel concept and not a filament concept.
EMMAN
EMMAN4mo ago
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:
/********************************************
* THIS 'MOUNT' WILL RUN EVERY REFRESH OF WEBSITE PAGE
*/
public function mount(): void
{
parent::mount();
$userId = Auth::user()->id ?? '0';
\Log::info("Hello world, current logged user ID is! $userId");

} /*
********************************************/
/********************************************
* THIS 'MOUNT' WILL RUN EVERY REFRESH OF WEBSITE PAGE
*/
public function mount(): void
{
parent::mount();
$userId = Auth::user()->id ?? '0';
\Log::info("Hello world, current logged user ID is! $userId");

} /*
********************************************/
Want results from more Discord servers?
Add your server