Make the Current user of the panel as an input to the form
Hello, I'm making something like: the admin puts information for the users,
The information should be marked in my db as that admin is the one who wrote it,
How should I do that?
9 Replies
Foreign id for admin like 'created_by'
yeah It's done in the model and the db all good,
but the form that I should fill requires typing the email of the current admin,
I don't want that, I want it to automatically bring it from the app
For this I have 2 options, you can choose whatever you like.
1. Mutate form before creating https://filamentphp.com/docs/2.x/admin/resources/creating-records#customizing-data-before-saving
2. Laravel Observer https://laravel.com/docs/10.x/eloquent#observers
if I precise more,
here
this is the nput
I want here instead of this, to make a function that brings the user email,
the function is already done, it just returns the email from the model
but how to assign it as an input 🥲
I don't understand what you're trying..
if
admin
is a relation in the model you can do
admin.email
now I'm doing this
In the create page, but that's obv wrong, how can I get the email here?
yes, but how to input that?
this should work
$data['admin'] = auth()->user()->email;
Yess, Worked!!
Thank you @Vp @Lara Zeus