Create SpendingsController with create and store functions
ADD
app/Http/Controllers/SpendingsController.php
+<?php
+
+namespace App\Http\Controllers;
+
+use Illuminate\Http\Request;
+
+use App\Spending;
+use App\Tag;
+
+use Auth;
+
+class SpendingsController extends Controller {
+ public function create() {
+ $tags = Tag::where('user_id', Auth::user()->id)->get();
+
+ return view('spendings.create', compact('tags'));
+ }
+
+ public function store(Request $request) {
+ $tag_id = $request->input('tag_id');
+ $date = $request->input('date');
+ $description = $request->input('description');
+ $amount = $request->input('amount');
+
+ $spending = new Spending;
+
+ $spending->user_id = Auth::user()->id;
+ $spending->tag_id = $tag_id;
+ $spending->date = $date;
+ $spending->description = $description;
+ $spending->amount = $amount;
+
+ $spending->save();
+
+ return redirect()->route('dashboard.index');
+ }
+}

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

ADD
resources/views/spendings/create.blade.php
+@extends('layout')
+
+@section('body')
+ <h1>Create spending</h1>
+ <div class="box">
+ <div class="box__section">
+ <form method="POST" action="/spendings">
+ {{ csrf_field() }}
+ <label>Tag</label>
+ <select name="tag_id">
+ <option value="">-</option>
+ @foreach ($tags as $tag)
+ <option value="{{ $tag->id }}">{{ $tag->name }}</option>
+ @endforeach
+ </select>
+ <label>Date</label>
+ <input type="text" name="date" />
+ <label>Description</label>
+ <input type="text" name="description" />
+ <label>Amount</label>
+ <input type="text" name="amount" />
+ <input type="submit" value="Create spending" />
+ </form>
+ </div>
+ </div>
+@endsection

MODIFY
routes/web.php
routes/web.php
@@ -8,6 +8,8 @@ Route::group(['middleware' => ['auth']], function () {
Route::resource('/earnings', 'EarningsController', ['only' => ['create', 'store']]);
+ Route::resource('/spendings', 'SpendingsController', ['only' => ['create', 'store']]);
+
Route::get('/reports', 'ReportsController@index')->name('reports.index');
Route::get('/reports/{year}/{month}', 'ReportsController@show')->name('reports.show');

Create SpendingsController with create and store functions