This is my store function in CategorieController.php
public function store(Request $request) {
Categorie::create([
'name'=>$request['name'],
]);
return redirect::to('/categorie');
}
and this is what I have in my model Categorie.php
class Categorie extends Model {
protected $table =['categories'];
protected $fillable=['name'];
}
but when I try to save my categorie into database I get this error:
ErrorException in Grammar.php line 39: Array to string conversion
$table variable used in your model is of type string.
protected $table = 'categories';
You should make changes in two places:
public function store(Request $request) {
Categorie::create([
'name' => $request->get('name'), // 1st place
]);
return redirect::to('/categorie');
}
And:
class Categorie extends Model {
protected $table = 'categories'; // 2nd place
protected $fillable = ['name'];
}
Explanation:
$table attribute of Model class which Categorie class extends from accepts a table name as string (Not Array) to link this model to it's corresponding table in database.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With