Laravel Custom blade directive

Step-1: Open App\Providers\AppServiceProvider.php
Step-2: Write the following code inside boot() method
Blade::directive('admin', function () {
$isAuth = 'false';
// check if the user authenticated is teacher
if (Auth::user() && Auth::user()->role== 2) {
$isAuth = 'true';
}

return "<?php if ($isAuth) { ?>";
});

Blade::directive('endadmin', function () {
return "<?php } ?>";
});
Step-3: Here Cache can be a problem: solve each time

php artisan cache:clear

php artisan config:clear

php artisan view:clear

Labels: ,

© copyright-2020 Rejaul