Issue
I am trying to write some code inside a laravel blade as shown below
@can('identical_trademark_local_show')
@php
$trimmed_payment_id=Str::substr($Payment->payment_id,0,9);
if($trimmed_payment_id=='AlYAFI:IL')
{
<a class="btn btn-xs btn-primary" href="{{ route('admin.identical-trademark-locals.show', $Payment->id) }}">
trans('global.view')
</a>"
}
if($trimmed_payment_id=='AlYAFI:SL')
{
<a class="btn btn-xs btn-primary" href="{{ route('admin.similarlocals.show', $Payment->id) }}">
trans('global.view')
</a>
}
if($trimmed_payment_id=='AlYAFI:SI')
{
<a class="btn btn-xs btn-primary" href="{{ route('admin.similarinternationals.show', $Payment->id) }}">
trans('global.view')
</a>
}
@endphp
@endcan
The problem is that am getting a syntax error
syntax error, unexpected '<'
Solution
You can't use the mustache {{ }}
symbol inside a @php
block and you need to write your HTML code outside of your @php
block
You'd be better off writing everything in blade syntax, one of the way to do it is as follow:
@can('identical_trademark_local_show')
@php
$trimmed_payment_id=Str::substr($Payment->payment_id,0,9);
@endphp
@if($trimmed_payment_id=='AlYAFI:IL')
<a class="btn btn-xs btn-primary" href="{{ route('admin.identical-trademark-locals.show', $Payment->id) }}">
trans('global.view')
</a>
@endif
@if($trimmed_payment_id=='AlYAFI:SL')
<a class="btn btn-xs btn-primary" href="{{ route('admin.similarlocals.show', $Payment->id) }}">
trans('global.view')
</a>
@endif
@if($trimmed_payment_id=='AlYAFI:SI')
<a class="btn btn-xs btn-primary" href="{{ route('admin.similarinternationals.show', $Payment->id) }}">
trans('global.view')
</a>
@endif
@endcan
NOTE
You should avoid the @php
block and instead pass on the value from your controller.
Answered By - Christophe Hubert Answer Checked By - Cary Denson (PHPFixing Admin)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.