Why use fillable in Laravel

Fillable is a protected property of a Model class and with the help of fillable property we can use short way to insert data into database like

User::create($request->all());

Or

$arrayOfData = ['name' => 'Doe', 'email' => 'test@test.com', ...];
User::create($arrayOfData);

Or

$user = new User;
$user->fill($arrayOfData);

Without fillable we need to write more code like

$user = new User;
$user->name = $request->input('name');
$user->email = $request->input('email');
...
...
$user->save();

Remember: Mass assignment vulnerability can occurs when we use fillable. To avoid use proper validation.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store