nwidart/laravel-modules 使用blade组件,无法使用组件变量
laravel-modules 8.2 版本
使用 php artisan module:make-component Alert Test, 成功创建 alert 组件(make-component 命令在 8.2 版本中无法使用,作者已经指出了 bug。解决方法)
modules 配置文件使用的默认配置文件,没有做任何更改。
在 blade 模板中使用该组件 (Modules/Test/ResourceViews/Components/alert.balde.php), 无法使用 Alert 类中的 $id 变量,测试 Alert 类没有执行。
<x-test::alert :id='$id'></x-test::alert>
Alert 组件类(Modules/Test/View/Component/Alert.php)
namespace Modules\Test\View\Component;
use Illuminate\View\Component;
class Alert extends Component
{
public $id;
/**
* Create a new component instance.
*
* @return void
*/
public function __construct()
{
//
$this->id = 'test-1'
}
/**
* Get the view / contents that represent the component.
*
* @return \Illuminate\View\View|string
*/
public function render()
{
return view('test::components.alert');
}
}
请高手指点,感谢!!
推荐文章: