php - 更改位置 Controllers\Auth
问题描述
我在 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'));
}
}
怎么了?我该如何修复它?
解决方案
您所做的更改全部来自应用程序的前端,但是当供应商/目录调用它时,它仍在尝试从同一命名空间访问与 Auth 相关的类,即
namespace App\Http\Controllers\Auth;
要成功更改 Auth 文件的命名空间,您需要告诉 Laravel 从 AuthServiceProvider.php 文件中访问这些文件的位置
app\Providers\AuthServiceProvider.php
那么就不会有那个class not found的问题
推荐阅读
- python - 从具有变量名的变量目录运行第二个 Python 脚本
- java - 在 JAVA fx 中设置标签的问题
- javascript - 表单提交返回内容类型为 application/json 而不是 text/html 的响应
- c - “文件指针”,“流”,“文件描述符”和......“文件”之间的区别?
- oracle - Oracle Apex 在批准者使用触发器和 Apex 邮件批准问题时发送电子邮件
- javascript - 在 codepen 中,Intersection 观察者的行为与浏览器窗口不同
- c# - 使用 Selenium C# 时的弹出/警报窗口
- maven - 跳过测试时,有没有办法使 mvn clean install 失败?
- javascript - vue-router 无法解析异步组件默认值:TypeError:无法读取未定义的属性“调用”
- android - React Native 未检测到 Android 模拟器