Add show function to SpendingsController
MODIFY
app/Http/Controllers/SpendingsController.php
app/Http/Controllers/SpendingsController.php
@@ -22,6 +22,16 @@ class SpendingsController extends Controller {
return view('spendings.index', compact('spendings', 'currency'));
}
+ public function show($id) {
+ $user = Auth::user();
+
+ $currency = $user->currency;
+
+ $spending = Spending::find($id);
+
+ return view('spendings.show', compact('currency', 'spending'));
+ }
+
public function create() {
$tags = Tag::where('user_id', Auth::user()->id)->get();

MODIFY
app/Spending.php
app/Spending.php
@@ -6,4 +6,8 @@ use Illuminate\Database\Eloquent\Model;
class Spending extends Model {
public $timestamps = false;
+
+ public function tag() {
+ return $this->belongsTo('App\Tag');
+ }
}

ADD
resources/views/spendings/show.blade.php
+@extends('layout')
+
+@section('body')
+ <div class="row spacing-bottom-large">
+ <div class="column">
+ <h1>{{ $spending->description }}</h1>
+ </div>
+ <div class="column">
+ <div class="box">
+ <table>
+ <tbody>
+ <tr>
+ <th>Date</th>
+ <td>{{ date('F jS, Y', strtotime($spending->date)) }}</td>
+ </tr>
+ <tr>
+ <th>Amount</th>
+ <td>{{ $currency->symbol }} {{ $spending->amount }}</td>
+ </tr>
+ <tr>
+ <th>Tag</th>
+ <td>{{ $spending->tag->name }}</td>
+ </tr>
+ </tbody>
+ </table>
+ </div>
+ </div>
+ </div>
+@endsection

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

Add show function to SpendingsController