Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

BloomWebbAB's avatar

Laravel 5.1 throws ReflectionException after upgrade from 5.0

I have recently upgraded Laravel to version 5.1 from 5.0, but whenever I send an API response to the server, it throws an exception like the following:

ReflectionException in RouteDependencyResolverTrait.php line 57: Class App\Http\Requests\User\GetRequest does not exist

Before upgrading everything was working fine.

This is the autoload section of my composer.json file:

"autoload": {
    "classmap": [
        "database"
    ],
    "psr-4": {
        "App\\": "app/",
        "Bloom\\" : "library/Bloom"
    }
}

Could it be that I did something went wrong during the upgrade procedure?

This is how the GetRequest class is declared:

<?php namespace App\Http\Requests\User;

use App\User;
use App\Http\Requests\Request;
use Illuminate\Support\Facades\Auth;

/**
 * Class GetRequest
 * @package App\Http\Requests\User
 */
class GetRequest extends Request {

Update: I just reinstalled Laravel 5.1 and moved all the old files to the new installation but I still receive the same error.

Update 2: After running php composer dump-autoload -o I can notice that the file vendor/composer/autoload_classmap.php contains the class that Laravel is unable to find:

 'App\\Http\\Requests\\User\\GetRequest' => $baseDir . '/app/Http/Requests/User/GetRequest.php',
0 likes
13 replies
BloomWebbAB's avatar

Sorry, that didn't solve the problem. I also updated my question.

tuneless's avatar

Hello @laracast-bloom , since there is no possibility to reproduce your case, please check all your namespaces. Maybe you have defined Namespaces and your files and paths do not match to them. Match your Namespaces to all Folder Paths. Just write, if it's all ok, because then, it's another issue.

BloomWebbAB's avatar

I can't find any error in my code.

I also tried to delete composer.lock and the vendor folder and then execute php composer install but that didn't work either.

I know that using artisan tinker I can do something like this:

use App\Http\Requests\User\GetRequest;
$getRequest = new GetRequest();

And that gives me an error because it's missing a parameter but it's not saying that the class can't be found.

BloomWebbAB's avatar

The folder is app/Http/Requests/User.

My editor PHPStorm is not complaining about missing classes. I really don't know what to think anymore.

tuneless's avatar

Ok, please give us your code, where you call GetRequest Maybe you have it in one Controller, but used a wrong Namespace.

BloomWebbAB's avatar
<?php namespace App\Http\Controllers;

use App\Http\Requests\User\GetRequest;
use Bloom\Product\Repository\UserRepositoryInterface;
use Bloom\Product\Transformers\UserTransformer;
use Illuminate\Http\Request;

/**
 * Class UserController
 * @package App\Http\Controllers
 */
class UserController extends APIController
{
    /**
     * @var UserRepositoryInterface
     */
    private $userRepository;

    /**
     * @param UserRepositoryInterface $userRepository
     */
    public function __construct(UserRepositoryInterface $userRepository)
    {
        $this->userRepository = $userRepository;
    }

    /**
     * @param GetRequest $request
     * @return \Symfony\Component\HttpFoundation\Response
     */
    public function get(GetRequest $request)
    {
        if(!$this->userRepository->getUser()) return $this->respondOK('User not found.');

        $user = $this->userRepository->getUser();

        return $this->respondOK('', (new UserTransformer())->transform($user->toArray()));
    }
}

I omitted all the other methods because all of them are causing the same issue. Of course the same is valid for all the other controllers.

As you can see I'm just following the Form Validation documentation.

bobbybouwmann's avatar

You miss the the use statement for the UserRepositoryInterface class and also for UserTransformer. Include the namespaces for them as well!

BloomWebbAB's avatar

Yes, I omitted them because they're not relevant, but they're included in the original file. I will update my previous post anyway.

BloomWebbAB's avatar

I tried also to create a new request using

php artisan make:request TestRequest

and then using the TestRequest in the UserController.php

/**
 * @param GetRequest $request
 * @return \Symfony\Component\HttpFoundation\Response
 */
public function get(TestRequest $request)
{
    if(!$this->userRepository->getUser()) return $this->respondOK('User not found.');

    $user = $this->userRepository->getUser();

    return $this->respondOK('', (new UserTransformer())->transform($user->toArray()));
}

but I still receive the same error.

BloomWebbAB's avatar
BloomWebbAB
OP
Best Answer
Level 6

OK, I found the solution.

I noticed that if in GetRequest class I swap use App\Http\Requests\Request; with use Request; then the GetRequest class is found and the ReflectionException is not thrown anymore.

So the problem is not in the App\Http\Requests\User\GetRequest class but in the abstract class App\Http\Requests\Request.

After looking at the App\Http\Requests\Request class, to which I made changes, I decided to replace it with the dist version from Laravel and then I reapplied my changes.

Long story short: The problem was in App\Http\Requests\Request because I made changes to it and something changed with the update to Laravel 5.1.

Please or to participate in this conversation.