如何在Laravel组件中传递对象属性值作为数据?

问题描述 投票:0回答:1

下面是我的组件标记input.blade.php。

<div>
    <div class="form-group"> 
        <label for="{{$name}}"> {{$label}}
            @if($required) </label><span class="text-danger pl-1">*</span> @endif
        <input 
            class="form-control" 
            onkeyup="document.getElementById('account_holder_name').value = this.value" 
            value="{{ old($name) ?? $value }}" 
            name="{{$name}}" 
            type="text" id="{{$name}}" 
            aria-required="{{$required}}" 
            required="{{$required}}">
    </div>
    @error("{{$name}}")
        <span class="text-danger">{{ $message }}</span>
    @enderror
</div>

我想通过 :value = $supplier->name 而不是下面,我通过

 @php $name = $supplier->name @endphp
 <x-forms.input type='text' name='name' label='Name' :value=$name required=true />
php laravel components
1个回答
0
投票

像这样吗?

<x-forms.input type="text" name="name" label="Name" value="{{$supplier->name}}" required="true" />
© www.soinside.com 2019 - 2024. All rights reserved.