【问题标题】:new link & controller produce Action Controller@index not defined error新链接和控制器产生 Action Controller@index not defined 错误
【发布时间】:2021-06-04 05:23:46
【问题描述】:

我正在创建一个我想用来管理员工数据的后端页面(使用 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');

    }
}

重新加载后页面显示以下错误:

错误异常(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 并没有改变我代码的当前行为。

我该如何纠正这个问题,我还可以检查哪些其他事项?

【问题讨论】:

    标签: php laravel laravel-blade


    【解决方案1】:

    在 Laravel 5.8 的 RouteServiceProvider 中,路由的命名空间被指向:

    应用程序/Http/控制器

    我认为他们在新的 Laravel 中删除了它。

    现在对于您的问题,您应该检查 RouteServiceProvider 指向的命名空间在哪里,然后在其上添加额外的“目录”;例如

    Route::get('/', 'App\Modules\Profiles\Controllers@index')->name('employeeprofiles.index');

    【讨论】:

      猜你喜欢
      • 2017-02-11
      • 2021-08-30
      • 2020-11-30
      • 2018-08-31
      • 2015-02-14
      • 1970-01-01
      • 1970-01-01
      • 2021-12-15
      • 2017-06-05
      相关资源
      最近更新 更多