Add ability to edit earnings
MODIFY
app/Earning.php
app/Earning.php
@@ -10,6 +10,8 @@ class Earning extends Model {
protected $dates = ['deleted_at'];
+ protected $fillable = ['description', 'amount'];
+
// Accessors
public function getFormattedAmountAttribute() {
return number_format($this->amount / 100, 2);

MODIFY
app/Http/Controllers/EarningController.php
app/Http/Controllers/EarningController.php
@@ -44,6 +44,25 @@ class EarningController extends Controller {
return redirect()->route('dashboard');
}
+ public function edit(Earning $earning) {
+ // TODO AUTHORIZE
+
+ return view('earnings.edit', compact('earning'));
+ }
+
+ public function update(Request $request, Earning $earning) {
+ // TODO AUTHORIZE
+
+ // TODO VALIDATE
+
+ $earning->fill([
+ 'description' => $request->input('description'),
+ 'amount' => $request->input('amount')
+ ])->save();
+
+ return redirect()->route('earnings.index');
+ }
+
public function destroy(Earning $earning) {
$this->authorize('delete', $earning);

ADD
resources/views/earnings/edit.blade.php
+@extends('layout')
+
+@section('body')
+ <div class="wrapper my-3">
+ <h2>{{ __('actions.edit') }} {{ __('general.earning') }}</h2>
+ <div class="box mt-3">
+ <form method="POST" action="/earnings/{{ $earning->id }}" autocomplete="off">
+ {{ method_field('PATCH') }}
+ {{ csrf_field() }}
+ <div class="box__section">
+ <div class="input input--small">
+ <label>Date</label>
+ <DatePicker></DatePicker>
+ @include('partials.validation_error', ['payload' => 'date'])
+ </div>
+ <div class="input input--small">
+ <label>Description</label>
+ <input type="text" name="description" value="{{ $earning->description }}" />
+ @include('partials.validation_error', ['payload' => 'description'])
+ </div>
+ <div class="input input--small mb-0">
+ <label>Amount</label>
+ <input type="text" name="amount" value="{{ $earning->amount }}" />
+ @include('partials.validation_error', ['payload' => 'amount'])
+ </div>
+ </div>
+ <div class="box__section box__section--highlight text-right">
+ <button class="button">@lang('actions.save')</button>
+ </div>
+ </form>
+ </div>
+ </div>
+@endsection

MODIFY
resources/views/earnings/index.blade.php
resources/views/earnings/index.blade.php
<div class="mt-1" style="font-size: 14px; font-weight: 600;">{{ $earning->formatted_happened_on }}</div>
</div>
<div class="row__column row__column--middle color-dark">{!! $currency !!} {{ $earning->formatted_amount }}</div>
- <div class="row__column row__column--middle row__column--compact">
+ <div class="row__column row__column--middle row row--right">
+ <div class="row__column row__column--compact">
+ <a href="/earnings/{{ $earning->id }}/edit">
+ <i class="far fa-pencil"></i>
+ </a>
+ </div>
+ <div class="row__column row__column--compact ml-2">
<form method="POST" action="/earnings/{{ $earning->id }}">
{{ method_field('DELETE') }}
{{ csrf_field() }}
</form>
</div>
</div>
+ </div>
@endforeach
@else
<div class="box__section text-center">You don't have any earnings</div>

MODIFY
routes/web.php
routes/web.php
@@ -15,6 +15,8 @@ Route::group(['middleware' => ['auth']], function () {
'index',
'create',
'store',
+ 'edit',
+ 'update',
'destroy'
]);

Add ability to edit earnings