Level 23
but why do you use Validator Facade, is there any specific reason?
use $request->validate(), this will take care of redirecting back to the input form , and will display any error message.
like this :
store method $request->validate example:
/**
* Store a newly created resource in storage.
*/
public function store(Request $request)
{
$validated = $request->validate([
'name' => ['required', 'string', 'max:200'],
'is_home' => ['required', 'string'],
'address' => ['nullable', 'string'],
'address_lat' => ['nullable', 'string'],
'address_long' => ['nullable', 'string'],
'address_obj' => ['nullable'],
'contact' => ['nullable', 'string', 'max:20'],
'support' => ['required', 'string'],
'remark' => ['nullable', 'max:1000'],
]);
Survey::create($validated);
flash()->addSuccess('Successfully Saved');
return to_route('surveys.index');
}
and Blade error code example:
<div class="form-floating mb-3">
<x-forms.text-input name="name" id="name" placeholder="enter your name"/>
<label for="floatingInput">Name</label>
<x-forms.error :messages="$errors->get('name')"/>
</div>
this may help you out!. let us know what you get.