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

ynoth25's avatar

Laravel @can blade directive

Greetings!

I have this page that uses include('src.modal') to include other .blade files and inside the modal I have @can directive that checks if user is authorized (@can('preview') ) on a single href element.

Result is that whenever the condition in @can is not met there exist an error that says modal not found. Is it normal for @can? Any help will be appreciated, thanks!

0 likes
2 replies
LaryAI's avatar
Level 58

It is normal for the @can directive to throw an error if the condition is not met. To prevent this, you can wrap the @can directive in an @if statement. For example:

@if (Auth::user()->can('preview'))
    @can('preview')
        <a href="/preview">Preview</a>
    @endcan
@endif

This will check if the user is authorized to preview before attempting to use the @can directive.

ynoth25's avatar

@LaryAI

So it is redundant as a result. But base on the error that I encountered it is the whole modal that does not exist even though I only put it on a single href code block.

Please or to participate in this conversation.