PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, November 16, 2022

[FIXED] When trying to insert data got this error msg Add [name] to fillable property to allow mass assignment on [App\Suitspecialist]

 November 16, 2022     get, laravel, laravel-6, post     No comments   

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)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing