0
votes

Using php artisan make:request StoreUserData I've create my rules to the request:

namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;

class StoreUserData extends FormRequest {
    public function rules(){
        return [
            'name'=>'required|integer',
            'surname'=>'required|max:255|string',
        ];
    }
}

And I'm trying to use it in controller

namespace App\Http\Controllers;
use Illuminate\Http\Request;

class UserDataController extends Controller {
    public function store(StoreUserData $request){
        return 'valid';
    }
}

Here the error I get: Class App\Http\Controllers\StoreUserData does not exist.

PS. Is not a problem of routing. I'm following this documentation since I'm using Laravel 5.6 https://laravel.com/docs/5.6/validation#creating-form-requests

1
composer dump-autoloadJ. Doe
Just tried @J.Doe still not working...Vixed
you forget to import StoreUserData, try adding use App\Http\Requests\StoreUserData in your controllerrkj
Yep @rkj thanks a lot!!! I'm so tired... Feel free to post it as answer, and I'll mark it as correct.Vixed
glad, it works for you. added as answerrkj

1 Answers

1
votes

Actually when you use StoreUserData in controller method then you have to import that class otherwise it will assume the class is in App\Http\Controllers namespace and thats why it throw Class App\Http\Controllers\StoreUserData does not exist.

just add the below import at top of your controller class

use App\Http\Requests\StoreUserData