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

r94ever's avatar

Custom Request Class not Found on VPS

Hi,

I am building an Laravel app for my customer. Since this is my first app using Laravel framework, so there are somethings I could not understand.

For the app, I have built it in my Windows computer with XAMPP. On this environtment, everything work fine. But when I deploy it to my VPS using LEMP stack, I met the problems with the Custom Request Class, which are extended from the FormRequest Class of Laravel.

The error message I got is:

ReflectionException
Class App\Http\Requests\Dashboard\Employees\GetEmployeesTableRequest does not exist

Others Custom Request Class has same error. I can sure that I created all of these classes via laravel command:

php artisan make:request Dashboard/Employees/GetEmployeesTableRequest

and so on.

I have also run this command: composer dump-autoload, as well as clear all cache. But they still there.

Now I really really don't know how to resolve this. If anyone can, please tell me what to do. Any help would be appreciated!

Thanks,

0 likes
10 replies
bobbybouwmann's avatar

How do you use your Request class in your controller? What is the namespace of the Request class? And is the Request in the same directory as the namespace?

This file should be in the `app/Http/Requests/Dashboard/Employees directory.

// GetEmployeesTableRequest.php

namespace App\Http\Requests\Dashboard\Employees;

class GetEmployeesTableRequest extends Request 
{

}

In your controller you will have something like this

// Controller
use App\Http\Requests\Dashboard\Employees\GetEmployeesTableRequest;

public function store(GetEmployeesTableRequest $request)
{

}
Snapey's avatar

You have gone from a case-insensitive development environment to a case-sensitive production environment

A common issue is having the wrong letter case somewhere.

r94ever's avatar

Thanks all for replying. The below is the content of GetEmployeesTableRequest.php

<?php

namespace App\Http\Requests\Dashboard\Employees;

use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Support\Facades\Gate;
use App\Exceptions\Authorization\GetEmployeeListPermissionException;
use Illuminate\Validation\ValidationException;

class GetEmployeesTableRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return Gate::allows('get_employees_list');
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        //
    }
    
    public function messages()
    {
        //
    }
    
    protected function failedAuthorization()
    {
        throw new GetEmployeeListPermissionException();
    }
    
    protected function failedValidation($validator)
    {
        throw new ValidationException($validator, jsonResponse($validator->errors()->first()));
    }
}

And this is content of EmployeeController.php

<?php

namespace App\Http\Controllers\Dashboard;

use App\Http\Controllers\Controller;
use App\User;
use App\Role;
use App\Http\Requests\Dashboard\Employees\GetEmployeesTableRequest;

class EmployeeController extends Controller
{    
    /**
     * Display a listing of the employees.
     *
     * @return \Illuminate\Http\Response
     */
    public function index(GetEmployeesTableRequest $request)
    {
        // get Employee list
       // Setup pagination data
        $perPage        = $request->query('per_page') ?? 20;
        $currentPage    = $request->query('page') ?? 1;
        
        // Setup Sorting
        $sortBy     = $request->query('sort_by') ?? 'id';
        $order      = $request->query('order') ?? 'desc';
        
        $roles      = $request->query('roles') ?? '';
        $status     = $request->query('resigned') ?? '';
        
        // Setup main query
        $data = User::with(['roles' => function ($q) use ($sortBy, $order) {
            $q->select('id', 'name');
            
            if ($sortBy === 'roles') {
                $q->orderBy('roles.name', $order);
            }
        }])->where('type', 'employee');
        
        // Setup roles filter
        if ($request->query('roles')) {
            $data = $data->whereHas('roles', function ($q) use ($request) {
                $q->where('id', $request->query('roles'));
            });
        }
        
        // Setup status filter
        if (is_numeric($request->query('resigned'))
                && ($request->query('resigned') == 0 || $request->query('resigned') == 1 ))
        {
            $data->where('resigned', $request->query('resigned'));
        }
        
        // Setup keyword
        if ($request->query('keyword')) {
            $keyword = explode(" ", trim($request->query('keyword')));
            
            foreach ($keyword as $k) {
                $data = $data->where(function($q) use ($k) {
                    $q->orWhere('name',  'LIKE', "%$k%");
                    $q->orWhere('email',     'LIKE', "%$k%");
                    $q->orWhere('tel',    'LIKE', "%$k%");
                    $q->orWhere('address',     'LIKE', "%$k%");
                    $q->orWhere('facebook',       'LIKE', "%$k%");
                });
            }
        }
        
        if ($sortBy !== 'roles') {
            $data = $data->orderBy($sortBy, $order);
        }
        
        $data = $data->paginate($perPage, ['*'], 'page', $currentPage);
       
        return view('dashboard.employees.index', [
            'employees'  => $data,
            'roles'      => Role::all('id', 'name'),
        ]);
    }
}

To @Snapey, I also though that it is the case sensitive error, but after checked, I can sure that is is impossible, because:

  1. I created these classes via Laravel commnd, and using Eclipse IDE to develop, which help me a lot for auto completing the method name, propertiy names, as well as import declaration etc.
  2. The app worked fine too when I run it to my Virtual machine which using Ubuntu 18.04 LTS (my VPS run Centos 7)
Snapey's avatar

And the request file and path is exactly App/Http/Requests/Dashboard/Employees/GetEmployeesTableRequest.php

r94ever's avatar

Almost, the App folder' name is app, not App

Cronix's avatar

Check the owner/permissions of all dirs leading to that file, including the file itself.

It could be you were logged in as a different user when running the artisan command

Snapey's avatar

dunno then. Its normally composer dump or a case sensitivity.

Does it appear in vendor/composer/autoload_classmap.php

r94ever's avatar

To @Cronix I have run the command chown -R nginx:nginx . at the root directory of Laravel app. Is it enough?

To @Snapey yes, it's already at there

// autoload_classmap.php @generated by Composer

$vendorDir = dirname(dirname(__FILE__));
$baseDir = dirname($vendorDir);

return array(
   //  ......................................
    'App\Http\Requests\Dashboard\Employees\GetEmployeesTableRequest' => $baseDir . '/app/Http/Requests/Dashboard/Employees/GetEmployeesTableRequest.php',
   //  ......................................
);
r94ever's avatar
r94ever
OP
Best Answer
Level 1

No answer. May be I have to use ubuntu instead of Centos

Please or to participate in this conversation.