小编Dan*_*Dan的帖子

以编程方式渲染 Laravel 7 组件

我有一个 Laravel 7 组件,如下所示

class Input extends Component
{
    public $name;
    public $title;
    public $value;
    public $type = 'text';

    /**
     * Create a new component instance.
     *
     * @return void
     */
    public function __construct($name, $title)
    {
        $this->name = $name;
        $this->title = $title;
        $this->value = \Form::getValueAttribute($name);
    }

    /**
     * Get the view / contents that represent the component.
     *
     * @return \Illuminate\View\View|string
     */
    public function render()
    {
        return view('components.fields.input');
    }
}
Run Code Online (Sandbox Code Playgroud)

我可以像这样在 Blade 组件中渲染该字段:

<x-input name="name" :title="__('My field')" />

我需要在代码中创建和渲染该字段,我尝试了以下操作:

$field …
Run Code Online (Sandbox Code Playgroud)

laravel laravel-blade laravel-7

8
推荐指数
4
解决办法
7966
查看次数

标签 统计

laravel ×1

laravel-7 ×1

laravel-blade ×1