Add fillable property to Tag model to be able to use create and fill methods in TagController
MODIFY
app/Http/Controllers/TagController.php
app/Http/Controllers/TagController.php
@@ -25,12 +25,10 @@ class TagController extends Controller {
public function store(Request $request) {
$request->validate($this->validationRules);
- $tag = new Tag;
-
- $tag->space_id = session('space')->id;
- $tag->name = $request->name;
-
- $tag->save();
+ Tag::create([
+ 'space_id' => session('space')->id,
+ 'name' => $request->input('name')
+ ]);
return redirect()->route('tags.index');
}
@@ -46,9 +44,9 @@ class TagController extends Controller {
$request->validate($this->validationRules);
- $tag->name = $request->input('name');
-
- $tag->save();
+ $tag->fill([
+ 'name' => $request->input('name')
+ ])->save();
return redirect()->route('tags.index');
}

MODIFY
app/Tag.php
app/Tag.php
@@ -10,6 +10,8 @@ class Tag extends Model {
protected $dates = ['deleted_at'];
+ protected $fillable = ['space_id', 'name'];
+
public function spendings() {
return $this->hasMany(Spending::class);
}

Add fillable property to Tag model to be able to use create and fill methods in TagController