Add startDate prop to DatePicker component and allow Earning model's happened_on field to be edited
MODIFY
app/Earning.php
app/Earning.php
@@ -10,7 +10,7 @@ class Earning extends Model {
protected $dates = ['deleted_at'];
- protected $fillable = ['description', 'amount'];
+ protected $fillable = ['happened_on', 'description', 'amount'];
// Accessors
public function getFormattedAmountAttribute() {

MODIFY
app/Http/Controllers/EarningController.php
app/Http/Controllers/EarningController.php
@@ -56,6 +56,7 @@ class EarningController extends Controller {
// TODO VALIDATE
$earning->fill([
+ 'happened_on' => $request->input('date'),
'description' => $request->input('description'),
'amount' => $request->input('amount')
])->save();

MODIFY
resources/assets/js/components/DatePicker.vue
resources/assets/js/components/DatePicker.vue
props: {
name: {
default: 'date'
+ },
+
+ startDate: {
+ default: null
}
},
return {
displayYear: new Date().getFullYear(),
displayMonth: new Date().getMonth() + 1,
- year: new Date().getFullYear(),
- month: new Date().getMonth() + 1,
- date: new Date().getDate()
+ year: this.startDate ? this.startDate.substring(0, 4) : new Date().getFullYear(),
+ month: this.startDate ? this.startDate.substring(5, 7) : new Date().getMonth() + 1,
+ date: this.startDate ? this.startDate.substring(8, 10) : new Date().getDate()
}
},

MODIFY
resources/views/earnings/edit.blade.php
resources/views/earnings/edit.blade.php
<div class="box__section">
<div class="input input--small">
<label>Date</label>
- <DatePicker></DatePicker>
+ <DatePicker start-date="{{ $earning->happened_on }}"></DatePicker>
@include('partials.validation_error', ['payload' => 'date'])
</div>
<div class="input input--small">

Add startDate prop to DatePicker component and allow Earning model's happened_on field to be edited