W
W
WebDev2016-01-27 16:38:32
Laravel
WebDev, 2016-01-27 16:38:32

Laravel FirstOrCreate Integrity constraint violation?

There is a ParamsValue model:

Schema::create('params_values', function (Blueprint $table) {
            $table->increments('id');
            $table->integer('param_id')->unsigned();
            $table->string('name');
            $table->timestamps();

            $table->foreign('param_id')
                ->references('id')
                ->on('params')
                ->onUpdate('cascade')
                ->onDelete('cascade');
        });

When trying to create a new value :
$param_value = ParamsValue::firstOrCreate(['id' => $id, 'param_id' => $param_id]);
                        $param_value->param_id = $param_id;
                        $param_value->name = $name;
                        $param_value->save();

I am getting an error:
MassAssignmentException in Model.php line 424:
id

I need to create a new value with the required param_id if there is no value with the same id and param_id.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
D', 2016-01-27
@kirill-93

Read to enlightenment here.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question