为什么在模板组件中使用模型会报错?

<?php

namespace App\View\Components\Common;

use Illuminate\View\Component;
use App\Models\CommonNav;

class Header extends Component
{
    /**
     * Create a new component instance.
     *
     * @return void
     */
    public function __construct()
    {
        //
    }

    /**
     * Get the view / contents that represent the component.
     *
     * @return \Illuminate\Contracts\View\View|\Closure|string
     */
    public function render(CommonNav $commonnav)
    {
        return view('components.common.header', compact('commonnav'));
    }
}

在模板组件中使用了 CommonNav 这个模型。然后方法中绑定模型,并且在返回时传递。这一系列流程哪里不对吗? 为什么会报下面这个错误呢

《L02 从零构建论坛系统》
以构建论坛项目 LaraBBS 为线索,展开对 Laravel 框架的全面学习。应用程序架构思路贴近 Laravel 框架的设计哲学。
《L01 基础入门》
我们将带你从零开发一个项目并部署到线上,本课程教授 Web 开发中专业、实用的技能,如 Git 工作流、Laravel Mix 前端工作流等。
最佳答案

你自定义的模板组件里的 render() 方法是实现了 use Illuminate\View\Component@render() 这个接口方法,参数需要保持一致,即无参

2年前 评论
ISeee (楼主) 2年前
zhaojjiang (作者) 2年前
ISeee (楼主) 2年前
讨论数量: 4

你自定义的模板组件里的 render() 方法是实现了 use Illuminate\View\Component@render() 这个接口方法,参数需要保持一致,即无参

2年前 评论
ISeee (楼主) 2年前
zhaojjiang (作者) 2年前
ISeee (楼主) 2年前