Solution:
Laravel has something called Mass Assignment. It let’s you pass an associative array and fills the model with those values. To make it work you have to define all the attributes you want to be able to mass assign in your model:
protected $fillable = ['foo', 'bar', 'and', 'much', 'more'];
Now you can just pass an array to the constructor of the model:
$input = [
'foo' => 'value1',
'bar' => 'value2',
'and' => 'value3',
'much' => 'value4',
'more' => 'value5',
];
$model = new Model($input);
$model->save();
Or even shorter, use the create()
method which fills the model and directly saves it afterwards:
Model::create($input);