Add destroy function to BudgetsController
MODIFY
app/Http/Controllers/BudgetsController.php
app/Http/Controllers/BudgetsController.php
@@ -40,4 +40,10 @@ class BudgetsController extends Controller {
return redirect('/budgets');
}
+
+ public function destroy($id) {
+ Budget::destroy($id);
+
+ return redirect('/budgets');
+ }
}

MODIFY
public/style.css
public/style.css
@@ -179,6 +179,20 @@ input[type=submit]:hover {
cursor: pointer;
}
+form.test {
+ display: inline-block;
+}
+
+form.test input[type=submit] {
+ background: none;
+ padding: 0;
+ color: #8B93A6;
+}
+
+form.test input[type=submit]:hover {
+ color: #4880FE;
+}
+
/* Spacing */
.spacing-top-small {

MODIFY
resources/views/budgets/index.blade.php
resources/views/budgets/index.blade.php
<td>@lang('months.' . $budget->month), {{ $budget->year }}</td>
<td>{{ $currency }} {{ $budget->amount }}</td>
<td>{{ $budget->tag->name }}</td>
+ <td>
+ <form class="test" method="POST" action="/budgets/{{ $budget->id }}">
+ {{ method_field('DELETE') }}
+ {{ csrf_field() }}
+ <input type="submit" value="Delete" />
+ </form>
+ </td>
</tr>
@endforeach
</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', 'create', 'store']]);
+ Route::resource('/budgets', 'BudgetsController', ['only' => ['index', 'create', 'store', 'destroy']]);
Route::resource('/tags', 'TagsController', ['only' => ['index', 'create', 'store']]);

Add destroy function to BudgetsController