laravel-5.4 - error :Creating default object from empty value laravel-5.4 - error :Creating default object from empty value database database

laravel-5.4 - error :Creating default object from empty value


you haven't initialized the variable $user so in the controller and before using it you've to add $user = new User; assuming that you already have use App\User;

or $user = new \App\User; if you don't.

Updateif you're trying to update an existing user record you've to initialize the $user variable by selecting based on it's primary key which should be sent in the request and then doing the initialization like:

$user_id = $request->input('user_id');$user = User::find($user_id);


Use the simple way below:

$user = User::where('id', '=', $id)->first(); // where id is method param from url or request object$user->save();

This is also easier when updating multiple tables where the ids in the sub-tables have foreign keys and need to be explicitly defined in the update process.

Also $user = User::find($id); normally work where the $id is the primary key of that object table