how to include an arrayed @if in laravel

89 Views Asked by At

I'm still a newbie in Laravel, I'm using Laravel 4.2 Is there a way where if the author_ID is matched with Auth::ID it will show the specific line of codes

Code blade example:

@if ($data['authorID'] == Auth::id())
    <a href="@{{invoice_url}}" target="_blank">
            @{{payment_date | date:_dateFormat.shortDate}}
    </a>
@else
    <p>@{{payment_date | date:_dateFormat.shortDate}}</p>
@endif

Where author_id's data is this

$data['authorID'] = [
                     author_id => 5,
                     author_id => 2
                     ]
3

There are 3 best solutions below

0
korugane On BEST ANSWER

I've found the solution instead of using @if I've used ng-if to get the result I want

<a href="@{{trx.invoice_url}}" target="_blank" ng-if= "auth_id == trx.author_id || role">
        @{{trx.payment_date | date:_dateFormat.shortDate}}
</a>
0
Mansoor Umer On

you should use in_array like this example $people = array("Peter","Joe","Glenn","Cleveland");

if (in_array("Glenn", $people))

{ echo "Match found"; } else{ echo "Match not found"; }

0
Bhola Kr. Khawas On

try this

@if (in_array(Auth::id(),$data['authorID']))
    <a href="@{{invoice_url}}" target="_blank">
            @{{payment_date | date:_dateFormat.shortDate}}
    </a>
@else
    <p>@{{payment_date | date:_dateFormat.shortDate}}</p>
@endif