doudi1449 2017-01-08 23:01
浏览 172
已采纳

如何解决Class App \ Http \ Requests \ UpdateUserRequest不存在? laravel 5.3

My code is like this :

<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;
use App\Models\User;

class UpdateUserRequest 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 User::$rules;

        return [
            'username' => 'required|unique:users,username,'. \Auth::user()->id;,
            'email' => 'required|unique:users,email,'. \Auth::user()->id;,
        ];
    }
}

It is a request to update user data

When the code is executed, there is an error like this:

ReflectionException in Route.php line 339: Class App\Http\Requests\UpdateUserRequest does not exist

How to solve the error?

  • 写回答

1条回答 默认 最新

  • dslkchyv673627 2017-01-08 23:18
    关注

    You have syntax errors in both of your rules:

    'username' => 'required|unique:users,username,'. \Auth::user()->id;,
    

    Remove the semicolon:

    'username' => 'required|unique:users,username,'. \Auth::user()->id,
    

    You may also run into issues if someone happens to submit the form without being logged in, but that may or may not be a concern for you.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?