Add create/function to BudgetsController
MODIFY
app/Budget.php
app/Budget.php
@@ -9,6 +9,8 @@ use App\Spending;
use Auth;
class Budget extends Model {
+ public $timestamps = false;
+
public function tag() {
return $this->belongsTo('App\Tag');
}

MODIFY
app/Http/Controllers/BudgetsController.php
app/Http/Controllers/BudgetsController.php
@@ -5,6 +5,7 @@ namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Auth;
+use App\Budget;
class BudgetsController extends Controller {
public function index() {
@@ -19,4 +20,24 @@ class BudgetsController extends Controller {
return view('budgets.index', compact('currency', 'budgets'));
}
+
+ public function create() {
+ $tags = Auth::user()->tags;
+
+ return view('budgets.create', compact('tags'));
+ }
+
+ public function store(Request $request) {
+ $budget = new Budget;
+
+ $budget->user_id = Auth::user()->id;
+ $budget->tag_id = $request->tag;
+ $budget->year = $request->year;
+ $budget->month = $request->month;
+ $budget->amount = $request->amount;
+
+ $budget->save();
+
+ return redirect('/budgets');
+ }
}

MODIFY
public/style.css
public/style.css
@@ -125,7 +125,7 @@ body {
/* Form */
-label, input {
+label, input, select {
display: block;
}
@@ -133,22 +133,27 @@ label {
margin-bottom: 8px;
}
-input {
+input, select {
font: inherit;
}
-input, .button {
+input, select, .button {
border-radius: 4px;
}
-input[type=text], input[type=email], input[type=password] {
+select {
+ -webkit-appearance: none;
+ background: #FFF;
+}
+
+input[type=text], input[type=email], input[type=password], select {
margin-bottom: 32px;
padding: 12px;
width: 100%;
border: 1px solid #E5E9F2;
}
-input[type=text]:focus, input[type=email]:focus, input[type=password]:focus {
+input[type=text]:focus, input[type=email]:focus, input[type=password]:focus, select:focus {
outline: 0;
}

ADD
resources/views/budgets/create.blade.php
+@extends('layout')
+
+@section('body')
+ <h1>Budgets &middot; Create</h1>
+ <div class="box spacing-small spacing-top-large">
+ <form method="POST" action="/budgets">
+ {{ csrf_field() }}
+ <label>Tag</label>
+ <select name="tag">
+ <option>-</option>
+ @foreach ($tags as $tag)
+ <option value="{{ $tag->id }}">{{ $tag->name }}</option>
+ @endforeach
+ </select>
+ <div class="row">
+ <div class="column">
+ <label>Year</label>
+ <input type="text" name="year" />
+ </div>
+ <div class="column">
+ <label>Month</label>
+ <select name="month">
+ <option>-</option>
+ @for ($month = 1; $month <= 12; $month ++)
+ <option value="{{ $month }}">@lang('months.' . $month)</option>
+ @endfor
+ </select>
+ </div>
+ </div>
+ <label>Amount</label>
+ <input type="text" name="amount" />
+ <input type="submit" value="Create" />
+ </form>
+ </div>
+@endsection

MODIFY
resources/views/budgets/index.blade.php
resources/views/budgets/index.blade.php
@extends('layout')
@section('body')
+ <div class="row">
+ <div class="column align-middle">
<h1>Budgets</h1>
+ </div>
+ <div class="column align-right">
+ <a href="/budgets/create" class="button">Create</a>
+ </div>
+ </div>
<div class="box spacing-top-large">
<table>
<tbody>

MODIFY
routes/web.php
routes/web.php
@@ -10,7 +10,7 @@ Route::group(['middleware' => ['auth']], function () {
Route::resource('/spendings', 'SpendingsController', ['only' => ['create', 'store']]);
- Route::resource('/budgets', 'BudgetsController', ['only' => ['index']]);
+ Route::resource('/budgets', 'BudgetsController', ['only' => ['index', 'create', 'store']]);
Route::resource('/tags', 'TagsController', ['only' => ['index', 'create', 'store']]);

Add create/function to BudgetsController