Create your own custom Blade directive in Laravel

1 · Amit Merchant · April 27, 2020, 6:45 a.m.
Laravel Blade comes with many in-built directives such as @section, @yield, @parent, @json and several others, all of which have a certain purpose attached to them. For instance, the @json directive can be used to encode JSON instead of directly using json_encode like so. <script> var app = @json($array); var app = @json($array, JSON_PRETTY_PRINT); </script> These, as I said, are in-built directives which comes with Laravel out-of-the-box. But what if you want to create your own custom...