I am using the @can
of policy in a view to show a button if the policy return true, And i want to send the variable $offer
to the policy the problem here is that the variable $offer
is not in the normal case because it's in a foreach loop of another varible, I will explain more:
Their is a foreach that loop a messages and every message has role the message can be a message sent from the user or admin and also can be an offer from the admin and here things start to be complicated by using the array inside array and in the final i have to send the array varible to the policy
I tried to send the variable $offer[($message->content - 1)]
like that and it's not working.
I tried also to replace the @can
by @if($offer[($message->content - 1)]->the_status != 'paid')
And it works but i need a policy because i will add others conditions
This is the can:
@can('accept', $offer[($message->content - 1)])
<button></button>
@include("layouts.modals.accept_offer")
@else
Paid
@endcan
The policy code is:
public function accept(User $user, Payments_offer $offer)
{
if($offer->the_status == 'paid')
{
return false;
}
return $user->id == $offer->user_id;
}
It work as like sending the class and not a variable
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire