Today in class we worked on our project 2 work, I have been so busy with other assignments (SDV701 assignment 2 stage 1 and WEB701 Milestone two) that I haven’t been able to devote as much time to project 2 as I would like.

In last weeks class I started going through a Laravel tutorial and I continued that today. However the tutorial had a missing step because I added a controller: UserController and two middleware which it calls: FirstMiddleware and SecondMiddleware however an error saying ‘Class ‘First” is missing’ was being displayed after much troubleshooting with Todd it was discovered that the FirstController was not added to the kernel.php which is the first file to be run in the site and it assigns the file path of FirstController to the field ‘First’ see below:

‘First’ => \RockandMineralSite\Http\Middleware\FirstMiddleware::class,

Then the web.php routing file is run and its logic is when the user writes in the HTTP request of ‘usercontroller/path’ (i.e. when they write that extension on the URL then the function ‘First’ in the associated ‘First’ middleware is run in addition to the showPath function in the UserController.php file (see below).

Route::get(‘usercontroller/path’,[
‘middleware’ => ‘First’,
‘uses’ => ‘UserController@showPath’,
]);

However Laravel does not know what the ‘First’ field is it is is not defined in the kernel.php and that was what was causing the whole problem.

So I have learned even if the tutorial doesn’t mention it you must always assign a middleware file path to a field in kernel.php

Advertisements