Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Eloquent creating empty record

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading