Reputation: 39
Hello I am making api of create venues The issue i am facing is that there are two users 1- Venue owner 2- user and what i want that i want to get the user_id which will create the venue but i cannot get the user_id in my venues table in database
My controller is
$venue = new Venue($request->all());
$venue->user_id = Auth::user()->user_id;
$venue->save();
$resultArray = ['status' => 1, 'message' => 'Venue created Successfully!', 'dataArray' => $venue];
In line second where i wrote Auth::user()->user_id; it says trying to get the property of non object i did not inlcude the middlewarre but when i include it perfectly worked fine but i dont want to use middleware i want to get the user_id without middleware. Help me !!!
Upvotes: 0
Views: 460
Reputation: 40909
You're most probably getting this error because you're executing this code as not authenticated user. Auth::user() returns NULL in such cases, hence the error.
Upvotes: 1