问题描述
我正在创建一个后端页面,我想用它来管理员工数据(使用 laravel 5.8)。我在侧边菜单刀片上添加了一个链接,指向员工概览页面。
链接:
<li class="nav-item">
<a href="{{ action('Profiles\Controllers\EmployeeController@index') }}"
class="nav-link {{ Request::is('admin') ? 'active' : null }}">
<i class="fas fa-user"></i> Employees
</a>
</li>
我还制作了一个控制器来获取我想要显示的数据,目前在函数中使用 dd()。
class EmployeeController extends Controller
{
public $model = CustomerLogin::class;
protected $views = 'WebshopCustomers::customerslogins ';
static $routes = ['index','create','store','edit','update','destroy'];
protected $datatableSelect = 'customer_logins';
protected $datatableRelations = ['roles','permissions'];
protected $datatableTrashed = true;
protected $datatableRawColumns = ['email','deleted_at'];
public function baseBreadcrumbs()
{
return [
['name' => 'Gebruikersbeheer']
];
}
public function index()
{
dd('test_index');
}
}
ErrorException (E_ERROR): 未定义 Action App\Modules\Profiles\Controllers\EmployeeController@index。 (视图:C:\xampp\htdocs\shopname\app\Modules\Backend\Views\partials\sidebar-default.blade.PHP)
路线: 我在谷歌上搜索了这个错误并阅读了建议以检查函数的路由是否存在(它不存在),所以我添加了它。
Route::get('/','EmployeeController@index')->name('employeeprofiles.index');
还提到将 RouteServiceProvider 中 $namespace 的值更改为 null,将其设置为 null 并没有改变我代码的当前行为。
我该如何纠正这个问题,我还可以检查哪些其他事项?
解决方法
在 Laravel 5.8 的 RouteServiceProvider 中,路由的命名空间被指向:
应用/Http/控制器
在新的 Laravel 中,我认为他们删除了它。
现在对于您的问题,您也应该检查 RouteServiceProvider 指向的命名空间在哪里,然后在其上添加额外的“目录”;例如
Route::get('/','App\Modules\Profiles\Controllers@index')->name('employeeprofiles.index');