add permits edit

This commit is contained in:
edmondlang
2024-01-30 00:07:31 +08:00
parent b64b25ff05
commit f389efa6af
9 changed files with 92 additions and 11 deletions
@@ -40,7 +40,7 @@ class ImportPermitsReminderController
$row['reminder_date'] = $this->changeExcelDate($row['reminder_date']);
$validator = Validator::make($row, [
'model' => 'required',
'model' => 'required|unique:permits_reminders,model',
'expiry_date' => 'required|date|after_or_equal:today',
'reminder_date' => 'required|date|after_or_equal:today',
]);
@@ -19,7 +19,7 @@ class CreatePermitsReminderController
{
// Define validation rules
$rules = [
'model' => 'required',
'model' => 'required|unique:permits_reminders,model',
'expiry_date' => 'required|date|after_or_equal:today',
'reminder_date' => 'required|date|after_or_equal:today',
];
@@ -0,0 +1,51 @@
<?php
namespace App\Http\Controllers\PermitsReminder;
use App\Models\PermitsReminder;
use Carbon\Carbon;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Validator;
class UpdatePermitsReminderController
{
/**
* @param Request $request
* @return JsonResponse
*/
public function update(Request $request): JsonResponse
{
$rules = [
'model' => 'required|unique:permits_reminders,model,' . $request->route('id'),
'expiry_date' => 'required|date|after_or_equal:today',
'reminder_date' => 'required|date|after_or_equal:today',
];
$validator = Validator::make($request->all(), $rules);
if ($validator->fails()) {
$validationErrors = $validator->errors()->all();
$validationError = implode("<br>", $validationErrors);
return response()->json([
'title' => 'Update Permits Reminder Failed',
'message' => $validationError,
"payload" => []
], 422);
}
$record = PermitsReminder::findOrFail($request->route('id'));
$record->model = $request->input('model');
$record->expiry_date = Carbon::parse($request->input('expiry_date'))->format('Y-m-d');
$record->reminder_date = Carbon::parse($request->input('reminder_date'))->format('Y-m-d');
$record->save();
return response()->json([
'title' => 'Permits Reminder Updated',
'message' => 'The permits reminder has been successfully updated.',
"payload" => $record
]);
}
}
+3 -3
View File
@@ -18,16 +18,16 @@ class PermitsReminder extends Model
public function getExpiryDateAttribute($value)
{
return Carbon::parse($this->created_at)->format('d-m-Y');
return $this->attributes['expiry_date'] === null ? NULL : Carbon::parse($this->attributes['expiry_date'])->format('d-m-Y');
}
public function getReminderDateAttribute($value)
{
return Carbon::parse($this->created_at)->format('d-m-Y');
return $this->attributes['reminder_date'] === null ? NULL : Carbon::parse($this->attributes['reminder_date'])->format('d-m-Y');
}
public function getCreatedAtAttribute($value)
{
return Carbon::parse($value)->format('d-m-Y');
return $this->attributes['created_at'] === null ? NULL : Carbon::parse($this->attributes['created_at'])->format('d-m-Y');
}
}
@@ -16,6 +16,7 @@
<add-permits-reminder-form-component
:section="section"></add-permits-reminder-form-component>
</modal-component>
<div class="btn btn-sm btn-default rounded b-rad-none" @click="refreshData"><i class="fa fa-refresh"></i></div>
</div>
</div>
<div class="row m-b-50" v-if="isUploadingCsv">
@@ -83,9 +84,14 @@
import { required } from "vuelidate/lib/validators";
export default {
props: {
section: {
type: String,
required: true
}
},
data() {
return {
section: 'orderProfileSection',
files: [],
parameters: {},
returnData: null,
@@ -112,7 +118,7 @@ export default {
this.parameters = {
files: this.files,
};
this.submit(this.route('api.permits_reminder.upload'), 'post', this.section, false, true);
this.submit(this.route('api.permits_reminder.upload'), 'post', this.section, true, true);
},
errorHandler(error) {
console.log(error);
@@ -123,6 +129,7 @@ export default {
},
refreshData() {
this.returnData = null;
this.isUploadingCsv = false;
this.key++;
}
},
@@ -87,6 +87,14 @@
:section="section">
</general-confirmation-form-component>
</modal-component>
<div class="btn bg-grey no-border muted requestModal" data-type="updateItem">
<i class="fa fa-edit"></i>
</div>
<modal-component class="animate__animated animate__fast animate__fadeIn"
type="updateItem">
<add-permits-reminder-form-component
:section="section" :existingData="data"></add-permits-reminder-form-component>
</modal-component>
</div>
</div>
</div>
@@ -3,7 +3,7 @@
<div class="col bg-white b-rad-lg">
<div class="row m-b-15">
<div class="col">
<h6 class="all-caps m-b-5 bold no-margin">Add PERMITS REMINDER</h6>
<h6 class="all-caps m-b-5 bold no-margin">{{ existingData ? 'Update' : 'Add' }} PERMITS REMINDER</h6>
</div>
</div>
<div class="row m-b-15 animate__animated animate__fadeInUpBig animate__fast" v-if="error">
@@ -53,6 +53,11 @@ import FormHandler from '../../../general/mixins/formHandler';
import { required } from "vuelidate/lib/validators";
export default {
props: {
existingData: {
type: Object,
}
},
data() {
return {
parameters: {
@@ -62,6 +67,13 @@ export default {
},
};
},
mounted() {
if (this.existingData) {
this.parameters.expiry_date = this.existingData.expiry_date;
this.parameters.reminder_date = this.existingData.reminder_date;
this.parameters.model = this.existingData.model;
}
},
validations: {
parameters: {
expiry_date: { required },
@@ -71,10 +83,12 @@ export default {
},
methods: {
submitForm() {
this.submit(this.route('api.permits_reminder.create'), 'post', this.section, true, true)
var apiRoute = this.existingData ? this.route('api.permits_reminder.update', this.existingData.id) : this.route('api.permits_reminder.create');
this.submit(apiRoute, 'post', this.section, true, true);
},
errorHandler(error) {
this.formHandler(error.message);
// this.formHandler(error.message);
console.log(error);
},
successHandler() {
this.closeModal();
+1 -1
View File
@@ -457,7 +457,7 @@
</div>
<div class="row m-b-20">
<div class="col">
<permits-reminder-component></permits-reminder-component>
<permits-reminder-component section="PermitsReminderComponent"></permits-reminder-component>
</div>
</div>
</div>
+1
View File
@@ -6,5 +6,6 @@ Route::group(['prefix' => 'permits-reminder', 'as' => 'permits_reminder.', 'name
Route::get('/list', 'ListPermitsReminderController@list')->name('list');
Route::post('/create', 'CreatePermitsReminderController@create')->name('create');
Route::delete('/{id}/delete', 'DeletePermitsReminderController@delete')->name('delete');
Route::post('/{id}/update', 'UpdatePermitsReminderController@update')->name('update');
});