I am having following html code in blade file:

@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`

I want to pass $engagement->id in roles[] as roles[{{@engegement_id}}]

However, instead of displaying value of {{@engegement_id}}, it is showing it as roles [{{@engegement_id}}] in html view source.

What am I doing wrong here?

2 Answers

0
Maulik Shah On

Try with this,

@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

Make string which you want to pass and store it in variable and pass that variable in Form select.

Hope this helps :)

0
Trupti On

We can not do like this, it is giving as error saying 'Undefined variable roles' for @php echo $roleWithId = roles[$engagement->id] @endphp. However, I tried it in select itself as

{!! Form::select('roles[@php echo $engagement->id @endphp]', $userRoles, $user->privileges->where(\App\Privilege::COLUMN_ENGAGEMENT_ID, $engagement-> {\App\Engagement::COLUMN_ID})->first()[\App\Privilege::COLUMN_ROLE]) !!}

However, it is showing it as

<select name="roles[<?php echo $engagement->id ?>]"> in view source