[Vuejs]-Method \UserController::sendError does not exist while trying to validate inputs laravel+vuejs

0👍

So this is how to create a standard request, you ‘can’ create them in the controller, but a more standard was of doing it is by making a FormRequest see documentation here https://laravel.com/docs/8.x/validation#creating-form-requests

You can create form requests using this command php artisan make:request StoreUserRequest

This way you can set the request in the params of the controller method as StoreUserRequest $request.

Then inside this Request you can set the rules much like you did here, but it will deal with the data failing automatically and it will return 422 and will return the errors, it will be quite deep in to the object that it returns, but it is there.

However if you do want to do validation in the controller you can access the ->errors() on the Validator.

Note:
Just a couple small things, I would take a look at https://laravel.com/docs/8.x/eloquent#inserts, which will show you an easier way of creating records.

And since all your fields look like they match the database, you can look at the $request->validated() method which will return all fields validated by the validator. This will be all fields that pass validation that are in the rules array.

Or you can use $request->only() or $request->except() and then array merge the password in and the fields you need to cast as a bool (banned and admin)

Leave a comment