What does "it doesn't work," mean? What does it do instead? Are you sure you don't have multiple rows with the same post_key?
Apr 22, 2018
30
Level 1
How to update the record if it exist or if not create new record
I want to create a draft if it doesn't exist. But if if there is a draft with the given post_key I want to update it, so..
Post::updateOrCreate(
// if there is a record with the given key update it or create new one
['post_key' => $data['post_key']],
[
'title' => $data['title'],
'slug' => str_slug($data['title']),
'content' => $data['content'],
'seo_title' => $data['seo_title'],
'seo_desc' => $data['seo_desc'],
'category_id' => $data['category_id'],
'post_status' => 0,
]);
But it doesn't work ?
Level 11
You are probably missing 'slug' from your $fillable attributes on the Model
1 like
Please or to participate in this conversation.