Answer the question
In order to leave comments, you need to log in
I uploaded a file to the server, there is a file address, I try to add the address to the buzz, I get an Error?
SQLSTATE[HY000]: General error: 1364 Field 'name' doesn't have a default value (SQL: insert into `users` (`photo`, `updated_at`, `created_at`) values (Uploads/kNHiAxuNxvoGE46jt6V4hejdFtYekFMRshQqP1mR.jpeg, 2020-07-01 13:01:45, 2020-07-01 13:01:45))
public function UploadAvatar(Request $r){
$av = $r->file('avatar')->store('Uploads','public');
$user = new Users;
$user->photo = $av;
$user->save();
return view('/my-account',['avatar'=>$user]);
}
Answer the question
In order to leave comments, you need to log in
The users table has a name field that doesn't have a default value, and in your insert you didn't set a value for that field. Here he is cursing. Give the name field a default value (for example, null), or specify some name:
You can also read about default values in relation to Eloquent: https://laravel.com/docs/7.x/eloquent#default-attr ...
$user->name = 'User name';
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question