I Have a problem when im trying to insert data inside my DB If the input field are not required, i cant insert any data with an empty field
/* This is my my model's code */
public function store(Request $request) { $this->validate($request,[ 'name' => 'required', 'email' => 'email', 'phone' => 'required', 'address' => 'required', ]);
$listing = new Listing;
$listing->name = $request->input('name');
$listing->email = $request->input('email');
$listing->website = $request->input('website');
$listing->phone = $request->input('phone');
$listing->adress = $request->input('address');
$listing->bio = $request->input('bio');
$listing->user_id = auth()->user()->id;
$listing->save();
return redirect('/dashboard')->with('success', 'Listing Added');
}
Hi
The message is about the foreign key user_id. It seems that auth()->user()->id is null or empty. Check if your user is logged before call the Auth method. If(auth()->check())
Thank you very much for reacting on my post. I found the errors and i correct it. I used the nullabe function into the database file. I'll post the code ASAP
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community