DEV Community

Discussion on: Understanding Mass Assignment in Laravel Eloquent ORM

Collapse
 
mazentouati profile image
Mazen Touati • Edited

Great breakdown I would like to add these extra tips:

  • If all of your table fields are fillable you should consider using protected $guarded = []

  • You can use $request->only(array $fields) to pick only certain columns.

  • Assuming you're using Laravel form request (learn more here) you can simply use $request->validated() to get the validated data.

PS: for tip 2 & 3 you probably should opt for protected $guarded = []

Collapse
 
zubairmohsin33 profile image
Zubair Mohsin

Hey thank you so much for sharing these tips. There are multiple ways to achieve the same objective. To get better understanding, I kept the options minimal.