Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

shez1983's avatar

Policies/Gates for custom things?

so i like the whole syntax @can().. but i wondered if i could do a custom one? ie if i have some logic:

if ( lesson has invoice, and invoice was attempted to be charged but failed) { 
     // show pay now button
}

or should i just create a helper func instead of attempting to use policies :s

0 likes
2 replies
m7vm7v's avatar
m7vm7v
Best Answer
Level 51

You could easily do that inside your LessonPolicy -

public function seeInvoiceWithFailedChargingAction(User $user, Lesson $lesson)
{
    if ( lesson has invoice, and invoice was attempted to be charged but failed) { 
        return true;
    }

    return false;
}

Then you can use @can('seeInvoiceWithFailedChargingAction', $lesson)

Hope that helps and guide you in the right direction.

1 like

Please or to participate in this conversation.