0

When I run `php artisan route:list' I get an error it can't find the RegisterController from the auth scaffolding.

Illuminate\Contracts\Container\BindingResolutionException  : Target class [App\Http\Controllers\Auth\RegisterController] does not exist.

  at C:\xampp\htdocs\antheap\vendor\laravel\framework\src\Illuminate\Container\Container.php:805
    801|
    802|         try {
    803|             $reflector = new ReflectionClass($concrete);
    804|         } catch (ReflectionException $e) {
  > 805|             throw new BindingResolutionException("Target class [$concrete] does not exist.", 0, $e);
    806|         }
    807|
    808|         // If the type is not instantiable, the developer is attempting to resolve
    809|         // an abstract type such as an Interface or Abstract Class and there is

  Exception trace:

  1   Illuminate\Foundation\Console\RouteListCommand::Illuminate\Foundation\Console\{closure}(Object(Illuminate\Routing\Route))
      [internal]:0

  2   ReflectionException::("Class App\Http\Controllers\Auth\RegisterController does not exist")
      C:\xampp\htdocs\antheap\vendor\laravel\framework\src\Illuminate\Container\Container.php:803

Which makes sense considering the RegisterController.php file is in Controllers/Web/Auth/ and its namespace is namespace App\Http\Controllers\Web\Auth;

I'm guessing it's looking for the wrong place because of default routing in the illuminate framework. However all the other Auth controllers are functioning fine. I'm not keen on moving everything just to make the list route:list command happy, though I kinda need it not crashing right now to help fix some other issue.


I've changed the Auth helper in web.php and added the auth routes:


// helper class generating all routes required for user authentication
// (authentication, registration and password resetting)
Auth::routes(['verify' => true, 'register' => false]);

Route::get('/login', 'Auth\LoginController@showLoginForm')->name('login');
Route::post('/login', 'Auth\LoginController@login');
Route::get('/logout', 'LoginController@logout')->name('logout');

Route::group(['middleware' => 'auth'], function () {
    Route::get('/password/confirm', 'Auth\ConfirmPasswordController@showConfirmForm')->name('password.confirm');
    Route::post('/password/confirm', 'Auth\ConfirmPasswordController@confirm');
});

Route::post('/password/email', 'Auth\ForgotPasswordController@sendResetLinkEmail')->name('password.email');

Route::get('/password/reset', 'Auth\ForgotPasswordController@showLinkRequestForm')->name('password.request');
Route::post('/password/reset', 'Auth\ForgotPasswordController@reset')->name('password.update');
Route::get('/password/password/reset/{token}', 'ResetPasswordController@showResetForm')->name('password.reset');

Route::group(['middleware' => 'guest'], function () {
    Route::get('/password/register', 'Auth\RegisterController@showRegistrationForm')->name('register');
    Route::post('/password/register', 'Auth\RegisterController@register');
});

However, this still doesn't allow for route:list to work correctly. The weird thing is I can comment out routes from about and they would still work normally (I assume covered by the default ones). Using route:clear doesn't change anything.

I can also add or remove the Auth\ in front of the Controller name, this doesn't keep it from working , nor will it fix route:list

But the app is definitely using it because if I change the URI suffix (like 'login' to 'logintest', it will show that in the browser address.

One thing that I forget to mention is that in RouteServiceProvide.php I added the \Web namespace (I don't know how route:list deals with that?)

    /**
     * Define the "web" routes for the application.
     *
     * These routes all receive session state, CSRF protection, etc.
     *
     * @return void
     */
    protected function mapWebRoutes()
    {
        Route::middleware('web')
            ->namespace($this->namespace . '\Web')
            ->group(base_path('routes/web.php'));
    }

This because I had to break up the route file at some point into multiple ones with their own namespaces. And I put the Auth inside the Web routes due to many of its routes using limited to no middleware.

Problem is that taking Auth from the web folder and namespace just breaks way more than just route:list.

  • Can you show us the web.php file where the controller actually called. – Apurv Bhavsar Dec 28 '21 at 16:58
  • The controllers that are created when generating the automatic auth Laravel scaffolding command, are never directly called in the web.php routing file. There is the small piece of code in the web.php: `Auth::routes(['verify' => true]);` which is a helper class generating all routes required for user authentication . – Stroomschok Dec 28 '21 at 17:15
  • Try with `php artisan route:clear` – STA Dec 28 '21 at 17:24
  • @sta sorry that doens't help. It's not a caching issue as I didn't change this recently. I think it's the command route:list trying to find the normal framework path for the auth controllers instead of the namespace and location they are given? – Stroomschok Dec 28 '21 at 17:27
  • Are you using laravel breeze or old scaffolding ? – Apurv Bhavsar Dec 28 '21 at 17:38
  • The old scaffolding. – Stroomschok Dec 28 '21 at 17:39
  • 1
    Auth routes are hardcoded and you need to manually specify your route if you changed the controller path. If the only route that isnt functioning is the register one, you could do `Auth::routes(['verify'=>true, 'register'=>false]);` and make a new route for register with the updated file path/namespace. – user3532758 Dec 28 '21 at 17:57
  • @user3532758 I tried your suggestion, but it didn't work (though it had some weird effects of not seeming fully supplanting the default routes). Code and explanation updated in the post. – Stroomschok Dec 28 '21 at 19:53
  • @miken32 Well I'm not using Laravel 8, but 7 and I do use the namespacing in the RouteServiceProvide (because of having to use multiple route files). The thing though is that everything is working just find with that, EXCEPT for the route:list command – Stroomschok Dec 28 '21 at 20:00
  • Why are you using the `Auth::routes()` helper and also manually defining the routes? Did you try just getting rid of the `Auth::routes()` call? Also your two routes at the bottom of the list clearly reference `App\Http\Controllers\Auth\RegisterController@register` which you're saying is the wrong namespace? – miken32 Dec 28 '21 at 20:01
  • Doesn't it do things besides just the registering? Like the verify thing? – Stroomschok Dec 28 '21 at 20:03
  • All the helper does is create routes. `verify => true` means it will add routes for password verification. – miken32 Dec 28 '21 at 20:04
  • Ok removed it, doesn't break anything. Still doesn't fix route:list though. And the bit about the Register routes I've tried multiple variations. They do get the Web prefix from the route serviceprovider (I don't know how that affect is it it's written full out starting with App\ like that) – Stroomschok Dec 28 '21 at 20:06
  • 1
    You really have too many inconsistencies here to get an idea of what the problem could be. I'd expect you to get errors on your /logout route as well unless you have a LoginController in both namespaces. Also ensure you're clearing route caches after these changes. Good luck. – miken32 Dec 28 '21 at 20:24

1 Answers1

0

Ok I solved it, but not in a pretty way by moving back all the auth controllers to the folder route:list was looking for and just adding another separate routing file solely for auth

RouteServiceProvider.php

    protected function mapAuthRoutes()
    {
        Route::middleware('web')
            // ->namespace($this->namespace . '\Auth')
            ->group(base_path('routes/auth.php'));
    }

I commented out the \Auth namespace because with testing it didn't seem to work properly

And then routes/auth.php

<?php

use Illuminate\Http\Request;
use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Route;
use Illuminate\Support\Facades\Session;

/*
|--------------------------------------------------------------------------
| Auth Routes
|--------------------------------------------------------------------------
|
*/

// helper class generating all routes required for user authentication
// (authentication, registration and password resetting)
// Auth::routes(['verify' => true, 'register' => false]);

Route::get('/login', 'App\Http\Controllers\Auth\LoginController@showLoginForm')->name('login');
Route::post('/login', 'App\Http\Controllers\Auth\LoginController@login');
Route::post('/logout', 'App\Http\Controllers\Auth\LoginController@logout')->name('logout');

Route::group(['middleware' => 'auth'], function () {
    Route::get('/password/confirm', 'App\Http\Controllers\Auth\ConfirmPasswordController@showConfirmForm')->name('password.confirm');
    Route::post('/password/confirm', 'App\Http\Controllers\Auth\ConfirmPasswordController@confirm');
});

Route::post('/password/email', 'App\Http\Controllers\Auth\ForgotPasswordController@sendResetLinkEmail')->name('password.email');

Route::get('/password/reset', 'App\Http\Controllers\Auth\ForgotPasswordController@showLinkRequestForm')->name('password.request');
Route::post('/password/reset', 'App\Http\Controllers\Auth\ForgotPasswordController@reset')->name('password.update');
Route::get('/password/password/reset/{token}', 'App\Http\Controllers\Auth\ResetPasswordController@showResetForm')->name('password.reset');

Route::group(['middleware' => 'guest'], function () {
    Route::get('/password/register', 'App\Http\Controllers\Auth\RegisterController@showRegistrationForm')->name('register');
    Route::post('/password/register', 'App\Http\Controllers\Auth\RegisterController@register');
});


I had to completely write out the paths for the controllers or it wouldn't work

And the namespace used in the auth controllers (which is also the file path):


namespace App\Http\Controllers\Auth;

use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\AuthenticatesUsers;

class LoginController extends Controller

I don't feel like this was the cleanest solution, and I would love to know why route:list doesn't seem to understand the namespacing used before. But at least it's working again now.