Support the ongoing development of Laravel.io →
Requests Input Database
Last updated 2 years ago.
0

The purpose of $fillable is exactly that, not allowing mass assignment!

Also, instead of $fillable, you can use $guarded , and you will add only the fields that are NOT fillable, might be easier maybe.

Going to your point, right now i'm out of my environment, so i can't test what i'm saying, but try and give feedback

$model = new Model;
$model->fill( $array ); // or $model->fill( ['field' => 'attribute', 'field2' => 'attribute2'] );
$model->field3 = 'attribute3';
$model->save();

the fill method will be protected against mass assignment, and when you set the attribute won't

Cheers

0

Thanks. Yes, I understand the purpose of $fillable, but you should be able to assign fields TO a mass assignment I guess is what I am saying.

Thanks for your help, I will give it a shot.

0

Hmmm if i got you right now, with what you want, does this give any help?


$vars = $request->all();

$vars_to_add = ['attribute3' => 'value3'];

$vars = array_merge($vars, $vars_to_add);

Model::create($vars);

Again, i'm just typing, cannot test, but you get the point

Cheers

Last updated 8 years ago.
0

Thanks but that would fall into a mass assignment and nonfillables would be ignored. Your previous method did work, I was just hoping for something more graceful. :)

Thanks again!

0

Sign in to participate in this thread!

Eventy

Your banner here too?

Jafo232 jafo232 Joined 6 Aug 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.