Hello, I am trying to make an image upload controller, all data is input into the database however the author which is supposed to be the user's id however whatever I use I am not able to get the user's id. I have used the following:
Auth::user()->id and
$request->user()->id
Is there any way to get the id from the currently logged in user while you're setting the data within the controller.
@SNAPEY - Yes it is, every index of the data array is in the fillable. I logged the user id before assigning it and it shows the correct Id with Auth::id() so I believe there is a problem when I try to assign it to $data['author']
$post = new Post();
$post->author = \Auth::id();
$post->fill($data) // make sure you comment/remove this line: $data['author'] = $request->user()->id;
$post->save();
Is anyone able to explain why it wasn't setting with the $data['author'] = \Auth::id() as this is still confusing me. I would assume this would work however it just doesn't want to set the value for some reason.