无法解析的依赖解析[Parameter #1[<required> $var]] in class App\View\Components\Header(View:laracurd\resources\views\welcome.blade.php)

问题描述

我的组件文件 header.PHP 代码如下

namespace App\View\Components;
use Illuminate\View\Component;
class Header extends Component
{  
    public $name;    
    public function __construct($name)
    {
      $this->name = $name;
      
    }
    public function render()
    {
        return view('components.header');
    }
}

我的welcome.baled.PHP 代码

<x-header  author="$name"/>

上面的代码把变量当成字符串,在view中渲染成$name,下面的代码正确渲染了结果的结果值

<x-header  author="{{$name}}"/>

如果我在welcome.blade.PHP 中绑定多个变量,我会收到以下错误

Illuminate\Contracts\Container\BindingResolutionException 无法解析的依赖解析类 App\View\Components\Header 中的 [Parameter #1 [ $writer]](视图:F:\RK\webapp\laracurd\resources\views\welcome.blade.PHP

*** 我的代码在welcome.blade.PHP ***

<x-header  author="{{$name}}" : writer="someContent"/>

*** header.PHP 组件文件中的我的代码***

public $name;
 public $writers;

public function __construct($name,$writer)
{
  $this->name = $name;
  $this->writers = $writer;
}

*** 我的代码在 header.blade.PHP 视图文件中 ***

<p>this is header Component area & the Book name is {{$name}},authors are following </p>
<h2>Authors Name : {{$writers}}</h2>

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)