猿问

在Laravel中,如何在name属性中显示php值?

我在刀片文件中有以下html代码:


@foreach ($engagements as $engagement)

    {!! Form::checkbox('engagements[]', $engagement->id, in_array($engagement->id, $user->privileges->pluck(engagement_id)->toArray()) ? true : false) !!} {{ $engagement->name }}

    {!! Form::select('roles[]', $userRoles, $user->privileges->where(engagement_id, $engagement->id)->first()[role]) !!}

@endforeach`

我想通过$engagement->id在roles[]如roles[{{@engegement_id}}]


但是,{{@engegement_id}}与其显示的值,不如将其显示为[{{@engegement_id}}]html视图源中的角色。


我在这里做错了什么?


侃侃尔雅
浏览 111回答 2
2回答

ABOUTYOU

我们不能这样,它给的错误是“未定义变量角色”&nbsp;@php echo $roleWithId = roles[$engagement->id] @endphp。但是,我尝试选择本身作为{!! Form::select('roles[@php echo $engagement->id @endphp]', $userRoles, $user->privileges->where(\App\Privilege::COLUMN_ENGAGEMENT_ID, $engagement-> &nbsp; {\App\Engagement::COLUMN_ID})->first()[\App\Privilege::COLUMN_ROLE]) !!}但是,它显示为<select name="roles[<?php echo $engagement->id ?>]">&nbsp;在查看源中

暮色呼如

试试这个@foreach ($engagements as $engagement)@php echo $roleWithId = roles[$engagement->id] @endphp{!! Form::checkbox('engagements[]', $engagement->id, in_array($engagement->id, $user->privileges->pluck(engagement_id)->toArray()) ? true : false) !!} {{ $engagement->name }}{!! Form::select($roleWithId , $userRoles, $user->privileges->where(engagement_id, $engagement->id)->first()[role]) !!}@endforeach生成要传递的字符串,并将其存储在变量中,然后在Formselect中传递该变量。
随时随地看视频慕课网APP
我要回答