Answer the question
In order to leave comments, you need to log in
How to get errors in laravel during ajax request and validation and return them in json format?
I create web. project, there will be a browser version, and api for mob. devices. I take out an array that will be rendered into a separate method, I plan to use this array for the web. version and for api. You need to get errors from CreateCarRequest and pass them on to the application.
How to get an array of errors?
protected function renderArray()
{
$cars = Cars::where(['user_id' => auth()->user()->id])
->with('status')
->get()
->toArray();
$renderArr = [
'cars' => $cars,
//'carStatuses' => CarStatus::all()->toArray()
];
return $renderArr;
}
public function index()
{
return view('car.index', $this->renderArray());
}
public function storage(CreateCarRequest $request)
{ }
Answer the question
In order to leave comments, you need to log in
Add a validator. For example
$validator = Validator::make(
array('name' => 'Дейл'),
array('name' => array('required', 'min:5'))
);
$validator->errors();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question