Create vs forceCreate

Nitish Kumar Singh
Nitish Kumar Singh
Clock Image 1 minutes
Posted on
March 20, 2020

Create vs forceCreate

Recently I came to know about this when I was trying to insert data into database. When I inserted the data I got error that mass assignable is not allowed.

What is mass assignable ?

When you try to insert more than one field of data in your database table then it becomes mass(more than one) assignable. If you like to create/edit more than one field in the table your need to mention that in Model.


namespace App;

use Illuminate\Database\Eloquent\Model;

class Post extends Model
    protected $fillable = [
        'title', 'content', 'category',

Now we can insert or modify all these fields at once.

If you don’t specify fields as fillable then you need to use forceCreate. It force the laravel to ignore the model fillable and force to insert the data in the database.

Last updated at Saturday, May 9, 2020 by Nitish Kumar Singh
comments powered by Disqus

Subscribe to our Newsletter

Tweet this article Tweet this article