creating default object from empty value laravel translatable code example

Example: creating default object from empty value laravel

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.

Update if 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);

Tags:

Php Example