Will this help you ?
https://laravel-livewire.com/docs/2.x/input-validation#access-validator-instance
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hello everyone! I am new to laracasts and also newish to livewire and laravel.
I am trying to use $this->validate on multiple models. It appears that $this->validate only validates the first $var. Is there any way to use $this->validate for all of the other $vars at the same time?
My code:
$validatedData_Class_Date_Bitmapp = $this->validate([
'Visible_Public' => 'required',
'Start_8AM' => 'required',
'DHS_Certified' => 'required',
'In_Person' => 'required',
'IL_Class' => 'required'
]);
Class_Date_BitmappModel::create($validatedData_Class_Date_Bitmapp);
$validatedData_Class_LocationModel = $this->validate([
'Location_Name' => 'required',
'Max_Students' => 'required'
]);
Class_LocationModel::create($validatedData_Class_LocationModel);
$validatedData_Class_DateModel = $this->validate([
'Course_ID' => 'required',
'Date' => 'required'
]);
Class_DateModel::create($validatedData_Class_DateModel);
$validatedData_Instructor_Model = $this->validate([
'Instructor_First_Name' => 'required'
]);
InstructorModel::create($validatedData_Instructor_Model);
$validated_Course_TypeModel = $this->validate([
'course_type_id' => 'required'
]);
Course_TypeModel::create($validated_Course_TypeModel);
// HOW TO USE $this->validate to validate ALL of the different models at once?
We validate the Request, not on the Models, so the validation should be a single step:
$validatedData = $this->validate([
'Visible_Public' => 'required',
'Start_8AM' => 'required',
'DHS_Certified' => 'required',
'In_Person' => 'required',
'IL_Class' => 'required',
'Location_Name' => 'required',
'Max_Students' => 'required',
'Course_ID' => 'required',
'Date' => 'required',
'Course_ID' => 'required',
'Date' => 'required',
'course_type_id' => 'required',
]);
// Then model creation
Class_Date_BitmappModel::create($request->only(['Visible_Public', 'Start_8AM', 'DHS_Certified', 'In_Person'));
// etc.
I would consider organising the form input names to namespace the different inputs, e.g.
<input name="bitmapp[Visible_Public]">
Please or to participate in this conversation.