Create details pages for earnings and spendings
MODIFY
app/Http/Controllers/EarningController.php
app/Http/Controllers/EarningController.php
@@ -18,6 +18,15 @@ class EarningController extends Controller {
];
}
+ public function show(Request $request, Earning $earning)
+ {
+ $this->authorize('view', $earning);
+
+ return view('earnings.show', [
+ 'earning' => $earning
+ ]);
+ }
+
public function create() {
return view('earnings.create');
}

MODIFY
app/Http/Controllers/SpendingController.php
app/Http/Controllers/SpendingController.php
@@ -17,6 +17,15 @@ class SpendingController extends Controller {
return view('spendings.create', compact('tags'));
}
+ public function show(Request $request, Spending $spending)
+ {
+ $this->authorize('view', $spending);
+
+ return view('spendings.show', [
+ 'spending' => $spending
+ ]);
+ }
+
public function store(Request $request) {
$request->validate([
'tag_id' => 'nullable|exists:tags,id', // TODO CHECK IF TAG BELONGS TO USER

MODIFY
app/Models/Earning.php
app/Models/Earning.php
@@ -32,5 +32,9 @@ class Earning extends Model {
}
// Relations
- //
+ public function attachments()
+ {
+ return $this->hasMany(Attachment::class, 'transaction_id')
+ ->where('transaction_type', 'earning');
+ }
}

MODIFY
app/Models/Spending.php
app/Models/Spending.php
@@ -50,4 +50,10 @@ class Spending extends Model {
public function tag() {
return $this->belongsTo(Tag::class);
}
+
+ public function attachments()
+ {
+ return $this->hasMany(Attachment::class, 'transaction_id')
+ ->where('transaction_type', 'spending');
+ }
}

MODIFY
resources/assets/sass/components/row.scss
resources/assets/sass/components/row.scss
.row {
display: flex;
- &.row--middle {
- align-items: center;
- }
+ &.row--middle { align-items: center; }
+ &.row--bottom { align-items: flex-end; }
- &.row--right {
- justify-content: flex-end;
- }
+ &.row--separate { justify-content: space-between; }
+ &.row--right { justify-content: flex-end; }
&.row--gutter {
margin-left: -20px;

ADD
resources/views/earnings/show.blade.php
+@extends('layout')
+
+@section('title', $earning->description)
+
+@section('body')
+ <div class="wrapper my-3">
+ <h2>{{ $earning->description }}</h2>
+ @include('partials.attachments', ['payload' => $earning])
+ </div>
+@endsection

ADD
resources/views/partials/attachments.blade.php
+<div class="row row--separate row--bottom mt-3 mb-1">
+ <h3>Attachments</h3>
+ <form method="POST" action="/attachments" enctype="multipart/form-data">
+ {{ csrf_field() }}
+ <input type="hidden" name="transaction_type" value="{{ get_class($payload) === 'App\Models\Earning' ? 'earning' : 'spending' }}" />
+ <input type="hidden" name="transaction_id" value="{{ $payload->id }}" />
+ <input type="file" name="file" onchange="this.form.submit()" />
+ </form>
+</div>
+<div class="box">
+ @if (!$payload->attachments->count())
+ <div class="box__section text-center">No attachments for this transaction</div>
+ @endif
+ @foreach ($payload->attachments as $attachment)
+ <div class="box__section">
+ <img src="{{ $attachment->file_path }}" style="max-width: 100%; max-height: 200px; border-radius: 5px; vertical-align: top;" />
+ </div>
+ @endforeach
+</div>

ADD
resources/views/spendings/show.blade.php
+@extends('layout')
+
+@section('title', $spending->description)
+
+@section('body')
+ <div class="wrapper my-3">
+ <h2>{{ $spending->description }}</h2>
+ @include('partials.attachments', ['payload' => $spending])
+ </div>
+@endsection

MODIFY
resources/views/transactions/index.blade.php
resources/views/transactions/index.blade.php
<div class="box__section row">
<div class="row__column row__column--middle row row--middle">
<div>{{ $transaction->description }}</div>
+ <a href="/{{ get_class($transaction) === 'App\Models\Earning' ? 'earnings' : 'spendings' }}/{{ $transaction->id }}">
+ <i class="fas fa-info-circle fa-xs c-light ml-1"></i>
+ </a>
<a href="/{{ get_class($transaction) === 'App\Models\Earning' ? 'earnings' : 'spendings' }}/{{ $transaction->id }}/edit">
<i class="fas fa-pencil fa-xs c-light ml-1"></i>
</a>

MODIFY
routes/web.php
routes/web.php
@@ -24,6 +24,7 @@ Route::group(['middleware' => ['auth']], function () {
});
Route::name('earnings.')->group(function () {
+ Route::get('/earnings/{earning}', 'EarningController@show')->name('show');
Route::get('/earnings/create', 'EarningController@create')->name('create');
Route::post('/earnings', 'EarningController@store');
Route::get('/earnings/{earning}/edit', 'EarningController@edit')->name('edit');
@@ -33,6 +34,7 @@ Route::group(['middleware' => ['auth']], function () {
});
Route::name('spendings.')->group(function () {
+ Route::get('/spendings/{spending}', 'SpendingController@show')->name('show');
Route::get('/spendings/create', 'SpendingController@create')->name('create');
Route::post('/spendings', 'SpendingController@store');
Route::get('/spendings/{spending}/edit', 'SpendingController@edit')->name('edit');

Create details pages for earnings and spendings