我制作了一个 Laravel 组件,使用php artisan make:component testcomponent它创建了两个文件;第一个是blade,第二个是php 类文件。这是刀片文件:
<div>
{{ $data }}
</div>
Run Code Online (Sandbox Code Playgroud)
这是 php 文件
<?php
namespace App\View\Components;
use Illuminate\View\Component;
class testcomponent 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()
{
return view('components.testcomponent');
}
}
Run Code Online (Sandbox Code Playgroud)
我使用这种方式在刀片文件中调用这个组件<x-testcomponent/>
但是现在,我如何将来自控制器的变量传递给该组件?