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

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

《L03 构架 API 服务器》
你将学到如 RESTFul 设计风格、PostMan 的使用、OAuth 流程,JWT 概念及使用 和 API 开发相关的进阶知识。
《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年前

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