I am using Laravel 8.
I am trying to validate inputs for creating users in the store method of my controller using requests.
Store method of my user controller
UserController.php
<?php
namespace AppHttpControllers;
use AppHttpRequestsUserCreateRequest;
use AppModelsUser;
use IlluminateHttpRequest;
use IlluminateSupportFacadesHash;
class UserController extends Controller
{
public function store(UserCreateRequest $request)
{
$user = User::create([
'name' => $request->input('name'),
'email' => $request->input('email'),
'password' => Hash::make($request->input('password')),
]);
return response($user, 201);
}
}
UserCreateRequest.php is the file I used to make validation.
UserCreateRequest.php
<?php
namespace AppHttpRequests;
use IlluminateFoundationHttpFormRequest;
class UserCreateRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'name' => 'required|min:3|max:25',
'email' => 'required|email',
];
}
}
But the problem is I get this error
{
"message": "Method Illuminate\Validation\Validator::validateRequierd does not exist.",
"exception": "BadMethodCallException",
"file": "/app/vendor/laravel/framework/src/Illuminate/Validation/Validator.php",
"line": 1395,
"trace": [
{
"file": "/app/vendor/laravel/framework/src/Illuminate/Validation/Validator.php",
"line": 554,
question from:
https://stackoverflow.com/questions/65871895/how-to-make-validations-with-requests-in-laravel-8 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…