Laravel FormRequest类投掷错误

时间:2018-06-03 01:00:06

标签: php laravel

这个类有问题,我得到错误Reflection Class not found,因为我在下面的类中的代码中有一些错误我试图在formRequest中为请求类清理我的输入。所以下面的代码中有一个错误,我不知道它是什么 - 它可能是一个错字或我不包括什么有人知道什么可能会抛出错误?

// SanitizeRequest类     

namespace App\Http\Forms;

use Illuminate\Foundation\Http\FormRequest;

class SanitizeRequest extends FormRequest
{
    private $clean = false;

    public function all(){
        return $this->sanitize(parent::all());
    }

    protected function sanitize(Array $inputs) {

        if($this->clean) { return $inputs; }

        foreach($inputs as $i => $item) { 

            if(is_string($item) && $i != 'file') {
                $inputs[$i] = trim($item);  
            }

            if(is_string($item) && !str_contains($i, 'html')) {
                $inputs[$i] = strip_tags($item);
            }            
        }

        $this->replace($inputs);
        $this->clean = true;

        return $inputs;
    }
}

// RolesRequest Class

<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;
use App\Http\Forms\SanitizeRequest;

use Auth;

class RolesRequest extends SanitizeRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return Auth::user()->hasRole('admin');
    }

    // public function all() it throws an error

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        switch($this->method())
        {
            case 'GET':
            case 'DELETE':
            {
                return [];
            }
            case 'POST':
            {
                $unique = [
                    'name'      => 'required|min:3|max:30|unique:roles,name',
                ];
                break;
            }
            case 'PUT':
            case 'PATCH':
            {
                $unique = [
                    'name'     => 'required|min:3|max:30|unique:roles,name,'. $this->id
                ];
                break;            
            }
            default:break;
        }      

        $rules = [
            'display_name' => 'required|min:4|max:50',
            'description'  => 'required|min:10|max:100'
        ]; 

        return $unique + $rules;       
    }
}

例外:

{message: "Class App\Http\Requests\RolesRequest does not exist", exception: "ReflectionException",…}
exception
:
"ReflectionException"
file
:
"C:\Users\me\Desktop\my_project\vendor\laravel\framework\src\Illuminate\Routing\RouteSignatureParameters.php"
line
:
25
message
:
"Class App\Http\Requests\RolesRequest does not exist"

0 个答案:

没有答案