Issue
Can anyone explain it to me why controller portion throwing error?
Here is my MODEL:
class Suitspecialist extends Authenticatable
{
use Notifiable;
protected $guard = 'suitspecialist';
protected $fillable = [
'name', 'email', 'password',
];
protected $hidden = [
'password', 'remember_token',
];
}
CONTROLLER
This portion throws an error
Add [name] to fillable property to allow mass assignment on [App\Suitspecialist].
protected function createSuitspecialist(Request $request)
{
$this->validator($request->all())->validate();
Suitspecialist::create([
'name' => $request->name,
'email' => $request->email,
'password' => Hash::make($request->password),
]);
return redirect()->intended('login/suitspecialist');
}
Solution
When you try to fill severeal properties on a model using a method like fill, create or update, you need to specify the fields that can be filled this way. This is call "mass assignment".
This is an Eloquent security implemented to avoid that you store data you don't want to.
In your model, use the guarded
or fillable
attributes to specify which properties you want or don't want to register use mass assignment. These properties accepts an array.
Look in the Laravel documentation it is well explained : https://laravel.com/docs/7.x/eloquent#mass-assignment
Answered By - Benjamin Masi Answer Checked By - Cary Denson (PHPFixing Admin)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.