Laravel consistency breaking when trying to use save
I am getting the error:
Integrity constraint violation: 19 NOT NULL constraint failed: songs.slug (SQL: insert into "songs" (values "title", "updated_at", "created_at") (as long as you love me, 2014-10-22 04:09:02, 2014-10-22 04:09:02))
when trying to update a song. Does anyone know what I am doing wrong?
Here is my update function:
public function update(Song $song, Request $request)
{
$song->fill(['title' => $request->get('title')])->save();
return redirect('songs');
}
Can someone help me understand what is wrong here? I am following Laracast to create this function and it looks like it should work just giving me this constraint error. HELP PLEASE :)
source to share
Make sure you have protected $fillable = ['title'];
one set in your Songs model as Laravel protects against bulk assignment (using -> fill ()) which means it will IGNORE any key / value you pass to the fill method which is not previously defined in the $ fillable property in your model!
source to share
As this error says
Integrity constraint violation: 19 NOT NULL constraint failed: songs.slug (SQL: insert into "songs" ("title", "updated_at", "created_at") values (As Long As You Love Me test, 2014-10-22 04:09:02, 2014-10-22 04:09:02))
slug
Your table column songs
is equal NOT NULL
and you did not set a value before saving your model.
source to share