Support the ongoing development of Laravel.io →
Input Requests Database

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');
}
Last updated 3 years ago.
0

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())

Last updated 6 years ago.
0

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

0

Sign in to participate in this thread!

Eventy

Your banner here too?

jozbruer jozbruer Joined 16 Feb 2019

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.