G
G
GrimJack2017-04-18 16:22:50
Laravel
GrimJack, 2017-04-18 16:22:50

Why is MassAssignmentException name thrown on create and fill?

In general, I'm trying to insert data into an empty table (too debug option)

public function adminCreate(){
        $insertData = [
            'calc' => [
                'name' => 'Новая печать',
                'slug' => 'novaya-pechat'
            ],
            'items' => [
                [
                    'name' => '1',
                    'img' => 'asd',
                    'price' => '500 руб'
                ]
            ]
        ];
        dd($this->insertCalc($insertData['calc']));

    }
    public function insertCalc($calcData){
        $calc = new Calculators();
        $calc->fill($calcData); 
        $calc->save();
        return $calc->id;
    }

And I fly out with errors "MassAssignmentException in Model.php line 225:
name"
Google did not give anything on the search. What could it be?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
H
hopeful_romantic, 2017-04-18
@GrimJack

In the Model try to add

/**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'field_name_1',
        'field_name_2',
    ];

https://laravel.com/docs/5.4/eloquent#mass-assignment

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question