在这里,我使用Laravel 11,将vue3替换为Blade . 所以我在inertiaJs的帮助下在Laravel框架内使用vue3
controller
public function addInfo(Request $request){
$validatedData = $request->validate([
'title' => 'required|string|max:25',
'message' => 'required|string',
'days' => 'required|integer|min:1',
]);
$count= Information::all()->count();
if($count >= 5){
$error = ([
'message'=> 'intonation not allowed more then 5 please delete old one',
'status' => false,
]);
return response()->json($error);
}
$new_info = new Information();
$new_info->title = $request->title;
$new_info->content = $request->message;
$new_info->days = $request->days;
$new_info->links = json_encode($request->links);
$new_info->save();
}
VUE3
const form = useForm({
title: '',
message: '',
days: '',
links:[],
});
form.post(route('info.add'), {
preserveScroll: true,
onSuccess: () =>{
form.reset();
lastInput.forEach(lastInput => {
lastInput.remove();
});
console.log(error);
showAlert('success', 'Info added Successfully');
},
onError: () => {
}
});
i want to know that how can i get return response()->json($error)
; to show in vue onError: ()
or any other process to show the error im using laravel web route