Eloquent creating empty record

Advertisements

I’m sure I’m doing something wrong but can’t figure out what it is.
In a controller I have a method which executes:

$estimate = Estimate::create(
  ['session_id' => 'test']
);

Model:
use HasFactory;

protected $fillable = ['width, height, direction_id, media_id, coating_id, shape_id, amount, qty, session_id'];

Estimate is related to estimates in my db.
When triggered an estimate record is created but the field ‘session_id’ is blank.

session_id is a VARCHAR 191.

Any idea why this is happening?

>Solution :

You define your $fillable wrong. It should be an array of strings:

protected $fillable = [
    'width',
    'height',
    'direction_id',
    'media_id',
    'coating_id',
    'shape_id',
    'amount',
    'qty',
    'session_id',
];

Leave a ReplyCancel reply