更改位置Controllers \ Auth

时间:2020-05-25 08:48:01

标签: php laravel laravel-5 laravel-7

我在Laravel 7中创建项目。 我将位置Http \ Controllers \ Auth更改为Http \ Controllers ** Admin ** \ Auth

在Auth目录中的所有文件中,我更改名称空间:

来自:

namespace App\Http\Controllers\Auth;

namespace App\Http\Controllers\Admin\Auth;

他们让作曲家转储自动加载。

登录正常。

现在,当我尝试使用我的代码注销时:

<a href="{{ route('logout') }}"
                       onclick="event.preventDefault(); document.getElementById('logout-form').submit();" class="btn btn-sm btn-light-primary font-weight-bolder py-2 px-5">Wyloguj</a>
                    <form id="logout-form" action="{{ route('logout') }}" method="POST" style="display: none;">
                        @csrf
                    </form>

我有错误:

Illuminate \ Contracts \ Container \ BindingResolutionException目标类 [App \ Http \ Controllers \ Front \ Auth \ LoginController]不存在。

我的RouteServiceProvider:

class RouteServiceProvider extends ServiceProvider
{
    /**
     * This namespace is applied to your controller routes.
     *
     * In addition, it is set as the URL generator's root namespace.
     *
     * @var string
     */
    protected $namespace = 'App\Http\Controllers';

    /**
     * The path to the "home" route for your application.
     *
     * @var string
     */
    public const HOME = '/';

    /**
     * Define your route model bindings, pattern filters, etc.
     *
     * @return void
     */
    public function boot()
    {
        //

        parent::boot();
    }

    /**
     * Define the routes for the application.
     *
     * @return void
     */
    public function map()
    {
        $this->mapApiRoutes();

        if(config('app.admin_only'))
        {
            $this->mapAdminOnlyRoutes();
        }
        else
        {
            $this->mapWebRoutes();
            $this->mapAdminRoutes();
        }
    }

    /**
     * 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. '\Front')
            ->group(base_path('routes/web.php'));
    }

    /**
     * Define the "api" routes for the application.
     *
     * These routes are typically stateless.
     *
     * @return void
     */
    protected function mapApiRoutes()
    {
        Route::prefix('api')
            ->middleware('api')
            ->namespace($this->namespace)
            ->group(base_path('routes/api.php'));
    }

    protected function mapAdminRoutes()
    {
        Route::prefix(config('app.admin_prefix'))
            ->middleware('web')
            ->namespace($this->namespace.'\Admin')
            ->group(base_path('routes/admin.php'));
    }

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

怎么了?我该如何修理?

1 个答案:

答案 0 :(得分:2)

您所做的更改全部来自应用程序的前端,但是当供应商/目录正在调用时,它仍试图从同一名称空间(即

)访问与Auth相关的类。
namespace App\Http\Controllers\Auth;

要成功更改Auth文件的名称空间,您需要告诉Laravel从位于其中的AuthServiceProvider.php文件访问这些文件的位置

app\Providers\AuthServiceProvider.php

那么就不会出现该类找不到的问题

相关问题