为什么在模板组件中使用模型会报错?
<?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 这个模型。然后方法中绑定模型,并且在返回时传递。这一系列流程哪里不对吗? 为什么会报下面这个错误呢
你自定义的模板组件里的
render()
方法是实现了use Illuminate\View\Component@render()
这个接口方法,参数需要保持一致,即无参