Group routes for SpendingController as a resource
MODIFY
app/Http/Controllers/SpendingController.php
app/Http/Controllers/SpendingController.php
@@ -50,6 +50,8 @@ class SpendingController extends Controller {
}
public function destroy(Spending $spending) {
+ $this->authorize('delete', $spending);
+
$spending->delete();
return redirect()->route('spendings.index');

MODIFY
routes/web.php
routes/web.php
@@ -16,10 +16,12 @@ Route::group(['middleware' => ['auth']], function () {
Route::post('/earnings', 'EarningController@store');
Route::delete('/earnings/{earning}', 'EarningController@destroy')->middleware('can:delete,earning');
- Route::get('/spendings', 'SpendingController@index')->name('spendings.index');
- Route::get('/spendings/create', 'SpendingController@create')->name('spendings.create');
- Route::post('/spendings', 'SpendingController@store');
- Route::delete('/spendings/{spending}', 'SpendingController@destroy')->middleware('can:delete,spending');
+ Route::resource('/spendings', 'SpendingController')->only([
+ 'index',
+ 'create',
+ 'store',
+ 'destroy'
+ ]);
Route::resource('/recurrings', 'RecurringController')->only(['index', 'show']);

Group routes for SpendingController as a resource