Confirmed /home
route does not work
Ran php artisan route:list
Got error Class App\Http\Controllers\ProductsController does not exist
Confirmed file ProductsController
does not actually exist
Searched for references to ProductsController
in code base
Found in routes/api.php
Commented out all lines in routes/api.php
that were referring to ProductsController
Ran php artisan route:list
again
Got a different error: Class App\Http\Controllers\Appointment does not exist
Found a reference to Appointment
(should be `AppointmentController) in web.php:
Route::get('/firstreport', 'Appointment@showLastAppointment');
Corrected and re-ran php artisan route:list
; saw an output of routes with no errors.
In this output, I see the following listed for the /home route:
Method: GET|HEAD
URI: home
Name: home
Action: App\Http\Controllers\HomeController@index
Middleware: web,auth
This suggests that the route /home
does in fact exist and should work.
But, I tested /home
again and it was still showing a Whoops error page with "Route not defined." error: screenshot.
Looking at frame #48 in the error page, we see reference to /app/Http/Middleware/Authenticate.php
, specifically this code:
/**
* Get the path the user should be redirected to when they are not authenticated.
*
* @param \Illuminate\Http\Request $request
* @return string
*/
protected function redirectTo($request)
{
return route('/home');
}
Note the syntax used here is return route('/home');
I think you wrote this thinking that upon auth failure, the user should be redirected to /home
.
Logically, this is what should happen. However, the redirectTo
method should not actually do/return the redirect - it should just return the path (as a String) to which the user should be redirected, per the comment: Get the path the user should be redirected to when they are not authenticated.
So instead you should write something like this:
return '/home'; # Return the path as a string by manually specifying it
Or, if the /home
route was named (it's not currently, but you could change that), you could use the route
helper method:
return route('home'); # Return the path as a string, getting it via the route helper method
Either approach would work.
However, you don't actually want to direct the user back to /home
upon auth failure, because it'd cause a redirect loop:
- user goes to /home ->
- they're not auth'd so they're redirected to /home ->
- user lands on /home ->
- they're not auth'd so they're redirected to /home ->
- etc. etc.
Instead, you probably want to have them redirected to the login page:
return '/login'; # Return the path as a string by manually specifying it
or
return route('login'); # Return the path as a string, getting it via the route helper method
(Note: by default - because you're using Auth::routes()
- the /login
route does have the name "login" so the latter approach would work).