1

I want to update data into table if the record exits if not then create a new record.

if(!empty($request->meta_title)){
    $meta = new \stdclass();
    $meta = VendorMeta::firstOrNew(['vendor_id' => $id]);
    $meta->meta_title = $data['meta_title'];
    $meta->meta_desc = $data['meta_desc'];
    $meta->meta_keyword = $data['meta_keyword'];
    $meta->save();    
}

But I am getting this error:

MassAssignmentException in Model.php line 445:vendor_id
1
  • First check meta_title available in your table and then decide.. Commented Nov 14, 2016 at 10:17

2 Answers 2

2

You should define which model attributes you want to make mass assignable, so in your VendorMeta class add following code:

protected $fillable = ['vendor_id'];
Sign up to request clarification or add additional context in comments.

1 Comment

If you find this answer correct, then mark this as accepted answer as it motivates me to answer more questions like this :D , and help others to get appropriate answers quickly.
1

You need to set the $fillable property on your model.

Take a look at the docs under Mass Assignment.

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.