In your model you can just add the protected $fillable property needed in case you need to mass assign values.
<?php
namespace App;
class Cat extends Model {
protected $fillable = ['name', 'color', 'lives'];
}
This means that if you want to send the Request from you views to you controller:
<?php
namespace App\Http\Controllers;
class CatController extends Controller {
public function store(Request $request) {
$cat = new Cat();
$cat->name = $request->input('name');
$cat->color = $request->input('color');
$cat->lives = $request->input('lives');
$cat->save();
return redirect()->route('cats.index')
->with('message', 'The cat ' . $cat->name . ' has been created successfully');
}
}
So aswering your question, the attributes of the Cat should be in the protected $fillable property.
Good Luck bro!
Thanks for an excellent answer. However fillable would never be a complete list as its only database fields that I want to be editable by request right? so if I could have a property that is legitimately not in that list. And the fillable list does not even hint at what type it should be.
Looking for something more concrete but I don't think its there.
Thanks and yes you're right, I guess you can always declare the properties in you model. Good Luck Ste.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community