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

<?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 这个模型。然后方法中绑定模型,并且在返回时传递。这一系列流程哪里不对吗? 为什么会报下面这个错误呢

《L04 微信小程序从零到发布》
从小程序个人账户申请开始,带你一步步进行开发一个微信小程序,直到提交微信控制台上线发布。
《L02 从零构建论坛系统》
以构建论坛项目 LaraBBS 为线索,展开对 Laravel 框架的全面学习。应用程序架构思路贴近 Laravel 框架的设计哲学。
最佳答案

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

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

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

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

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!