Add create/store functions to TagsController
MODIFY
app/Http/Controllers/TagsController.php
app/Http/Controllers/TagsController.php
@@ -5,7 +5,7 @@ namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Auth;
-use App\Tags;
+use App\Tag;
class TagsController extends Controller {
public function index() {
@@ -13,4 +13,19 @@ class TagsController extends Controller {
return view('tags.index', compact('tags'));
}
+
+ public function create() {
+ return view('tags.create');
+ }
+
+ public function store(Request $request) {
+ $tag = new Tag;
+
+ $tag->user_id = Auth::user()->id;
+ $tag->name = $request->name;
+
+ $tag->save();
+
+ return redirect('/tags');
+ }
}

MODIFY
app/Tag.php
app/Tag.php
@@ -5,5 +5,5 @@ namespace App;
use Illuminate\Database\Eloquent\Model;
class Tag extends Model {
- //
+ public $timestamps = false;
}

ADD
resources/views/tags/create.blade.php
+@extends('layout')
+
+@section('body')
+ <h1>Tags PLACEHOLDER Create</h1>
+ <div class="box spacing-small spacing-top-large">
+ <form method="POST" action="/tags">
+ {{ csrf_field() }}
+ <label>Name</label>
+ <input type="text" name="name" />
+ <input type="submit" value="Create" />
+ </form>
+ </div>
+@endsection

MODIFY
resources/views/tags/index.blade.php
resources/views/tags/index.blade.php
<h1>Tags</h1>
</div>
<div class="column align-right">
- <a href="#" class="button">Create</a>
+ <a href="/tags/create" class="button">Create</a>
</div>
</div>
<div class="box spacing-top-large">

MODIFY
routes/web.php
routes/web.php
@@ -12,7 +12,7 @@ Route::group(['middleware' => ['auth']], function () {
Route::resource('/budgets', 'BudgetsController', ['only' => ['index']]);
- Route::resource('/tags', 'TagsController', ['only' => ['index']]);
+ Route::resource('/tags', 'TagsController', ['only' => ['index', 'create', 'store']]);
Route::get('/reports', 'ReportsController@index')->name('reports.index');
Route::get('/reports/{year}/{month}', 'ReportsController@show')->name('reports.show');

Add create/store functions to TagsController