I'm doing a dashboard frontend for a Laravel back-end, and there are a lot of ajax requests from many sources, my end goal is to have a file like api.js that encapsulates all my api logic, I wanted to be able to reuse Laravel validation rules to validate all my api requests.
example form request:
<?php
namespace App\Http\Requests\DoctorProfile;
use App\Http\Requests\ApiRequest;
class GetAppointments extends ApiRequest
{
...
public function rules()
{
return [
'doctor_id' => 'required|integer|min:0',
'date' => 'date_format:Y-m-d',
];
}
...
}
I searched and found these two libraries:
these two are good but the problem is they both focus on Form elements but there are many requests that still need validation but the values don't exist in a single form!
I thought about it and a possible hack is to have a hidden Form and i can add values to it via js then use Laravel Javascript Validation to send the request.
I don't have that much front-end experience so i wanted to ask here and make sure im not doing anything terribly wrong bfore resorting to such hacks:D
requiredandtype="number"on a field or something, or we're misunderstanding each other.sometimesLaravel validation. Fetching data on mouse-hover or click has nothing to do with validation, if you make sure you return the data in a certain way to the graph, why would you need the 'frontend validation' for anything?