Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Class does not exist - Laravel

Tags:

php

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.

like image 401
prgrm Avatar asked Oct 05 '16 10:10

prgrm


People also ask

What is reflection exception?

A ReflectionException occurs when there's an error while performing any sort of reflection; specifically when dealing with the Reflector , or with other classes that inherit from it.


1 Answers

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.

like image 67
Duarte Fernandes Avatar answered Oct 08 '22 07:10

Duarte Fernandes