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

Aqeel94321's avatar

Can its possible to append @can() @endcan blade directive using ajax request

I have one question can its possible to append blade directive from ajax request on success...

$('.data').append('@can('report excel-download' )\n' +
                    '    <div class="col-md-6">\n' +
                    '        <a href="/download/xlsx/?filter=result.request.filter"\n' +
                    '           class="excel mb-2 btn-icon btn-shadow btn-sm btn btn-outline-success float-right">\n' +
                    '        <i class="lnr-download"> Export as Excel </i></a>\n' +
                    '    </div>\n' +
                    '@endcan');

Can it is possible? Thank in advance.

0 likes
4 replies
MichalOravec's avatar

It's not possible. On the server check if it can be appended, if so then just append it without that blade directive.

MichalOravec's avatar

On the server

return response()->json([
    'canDonwload' => Auth::user()->can('report excel-download'),
    // other things
]);

In the callback of jQuery ajax

if (data.canDonwload) {
    // here append html
}
1 like

Please or to participate in this conversation.