Home > Software design >  Eloquent creating empty record
Eloquent creating empty record

Time:02-04

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?

CodePudding user response:

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',
];

CodePudding user response:

try protected $guarded = []; in model

  • Related