1

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 App\Http\Controllers;

use App\Http\Requests\UserCreateRequest;
use App\Models\User;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Hash;

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 App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;



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,
3
  • 1
    Looks all good, but it seems you made a typo somewhere because it tries to call validateRequierd and not validateRequired. You probably wrote requierd somethere in your validation rules. Commented Jan 24, 2021 at 14:54
  • Found it. Cannot believe it made me scratch my head so much. Use it answer it with this. And I will accept your answer. @codedge Commented Jan 24, 2021 at 15:00
  • Set password as required field. Commented Jan 24, 2021 at 22:06

1 Answer 1

2

Looks all good, but it seems you made a typo somewhere because it tries to call validateRequierd and not validateRequired. You probably wrote requierd somethere in your validation rules.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.