在刀片表单组件中包括Auth

时间:2019-07-30 00:35:50

标签: php laravel laravel-blade

我有以下代码:

<div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
    @include('component.input',[
        'label' => 'Last Name',
        'name' => 'last_name',
        'type' => 'text',
        'placeholder' => 'Li',
        'class' => '',
        'errorMessage' => "required"
    ])
</div>

我想做类似的事情:

<div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
    @include('component.input',[
        'label' => 'Last Name',
        'name' => 'last_name',
        'type' => 'text',
        'placeholder' => "{{Auth::user()->last_name}}"
        'class' => '',
        'errorMessage' => "required"
    ])
</div>

但是返回语法错误。

1 个答案:

答案 0 :(得分:0)

您在@include标记内时处于PHP上下文中,因此您可以直接使用Facade:

<div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
    @include('component.input',[
        'label' => 'Last Name',
        'name' => 'last_name',
        'type' => 'text',
        'placeholder' => Auth::user()->last_name,
        'class' => '',
        'errorMessage' => "required"
    ])
</div>