One solution to this problem is to perform the authorization check outside of the loop and store the result in a variable. Then, use that variable inside the loop to conditionally display the action button. This way, the authorization check is only performed once instead of for every row in the loop.
Here's an example implementation:
@php
$canEdit = auth()->user()->can('some.permission');
@endphp
@foreach($models as $model)
<td>{{$model->someData}}</td>
<td>
@if($canEdit)
<a href="{{route('some.route', $model)}}">
<i class="fas fa-eye"></i>
</a>
@endif
</td>
@endforeach
In this example, we're using the @php directive to perform the authorization check and store the result in the $canEdit variable. Then, inside the loop, we're using an @if directive to conditionally display the action button based on the value of $canEdit.
By performing the authorization check outside of the loop, we're reducing the number of times the check needs to be performed, which can improve performance.