Closed NeguinhoAdmin closed 2 weeks ago
Hello @NeguinhoAdmin
Did you try using a validation restriction? Something like combine date + time need to be unique.
Cheers.
No I havnt, I was thinking to put constrain on database "unique together" but it is huge probability that it will accept it anyway because of minutes , seconds , or milli-second.
Hi,
At least unique together works for me. So, same slot cannot be issued to someone.
Now i need to think how to give appropriate message instead of that 500 error.
Thank you.
Hello @ShariqAyaz
Can you share the request validation you write, because if you write correctly there is a beautiful message, not an SQL error.
Cheers.
I believe you asking this?
public function rules()
{
return [
'branch_id' => 'required|exists:branches,id',
'title' => 'nullable|string',
'date_of_appointment' => 'nullable|date',
'start' => 'nullable|date',
'end' => 'nullable|date',
'vehicle_registration' => 'required|string',
'vehicle_chassis' => 'nullable|string',
'vehicle_color' => 'nullable|string',
'all_day' => 'nullable|boolean',
'customer_name' => 'required|string',
'customer_contact' => 'required|string',
'customer_email' => 'required|email',
'notes' => 'nullable|string',
'background_color' => 'nullable|string',
'text_color' => 'nullable|string',
'start' => [
'nullable',
'date',
function ($attribute, $value, $fail) {
$end = request('end');
if ($value && $end) {
$exists = \App\Models\MOTBooking::where('start', $value)
->where('end', $end)
->exists();
if ($exists) {
$fail('The combination of start and end times must be unique.');
}
}
},
],
];
}
I have recently added this.
'start' => [
'nullable',
'date',
function ($attribute, $value, $fail) {
$end = request('end');
if ($value && $end) {
$exists = \App\Models\MOTBooking::where('start', $value)
->where('end', $end)
->exists();
if ($exists) {
$fail('The combination of start and end times must be unique.');
}
}
},
],
Hello @ShariqAyaz
Can you share the request validation you write, because if you write correctly there is a beautiful message, not an SQL error.
Cheers.
Done ...! Cheers
in your code you have "start" rule declare two times, i think laravel ignore the second declaration.
Try to fix it please.
Cheers.
Did you try it?
Cheers.
yes, it is tested working fine now.
Im glad the issue is solve. I will close the issue, but please feel free to re-open or create a new one if needed.
Cheers.
Issues "Calendar Operation backpack/calendar-operation"
Currently, I am trying to restrict timeslot, so same time no more than one slot can be booked, I am looking for organic or systematic way.
If no than, I need to understand where I could change calendar behaviour. So, I do customise it.
this is what i want to stop it/fix it(not more than two slots):
Thank you