0

there is something wrong with this class and I get the error Reflection Class not found because I have some kind of error in my code in the class below I'm trying to sanitize my inputs in a formRequest for a request class. So the code below has an error in it and I don't know what it is - it could be a typo or I'm not including something does anyone know what might be throwing the error?

// SanitizeRequest Class

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;       
    }
}

Exception:

{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"
ONYX
  • 5,679
  • 15
  • 83
  • 146

0 Answers0