prgrm
prgrm

Reputation: 3833

Class does not exist - Laravel

I am following this tutorial. I am currently using laravel 5.3 so it is a little outdated. I have done step by step as said by the tutorial, however, I get

   ReflectionException in Container.php line 749:
   Class First does not exist

in Container.php line 749
at ReflectionClass->__construct('First') in Container.php line 749
at Container->build('First', array()) in Container.php line 644
at Container->make('First', array()) in Application.php line 709
at Application->make('First') in Kernel.php line 173
at Kernel->terminate(object(Request), object(Response)) in index.php line 58
at require_once('C:\xampp5\htdocs\laravel\laravel\public\index.php') in server.php line 21

Everything is just like in the tutorial. I have no idea where could be the problem.

Upvotes: 5

Views: 2338

Answers (1)

Duarte Fernandes
Duarte Fernandes

Reputation: 118

The problem is that you created a FirstMiddleware but you referred to it only as First here:

<?php
Route::get('/usercontroller/path',[
   'middleware' => 'First',
   'uses' => 'UserController@showPath'
]);

As stated in the official docs,

if you would like to assign middleware to specific routes, you should first assign the middleware a key in your app/Http/Kernel.php

So, add this to your app/Http/Kernel.php file:

protected $routeMiddleware = [
    // the other route middlewares are defined here
    'First' => \App\Http\Middleware\FirstMiddleware::class, // add this line
]

I think this should be enough.

Upvotes: 10

Related Questions