create new service provider
Creating Custom Laravel Blade Directive | create new service provider
php artisan make:provider BladeServiceProvider
register in
config/app.php
Add below to the $providers array.
App\Providers\BladeServiceProvider::class,
Add below code in BladeServiceProvider‘s boot() method.
Blade::directive('routeis', function ($expression) {
return "<?php if (fnmatch({$expression}, Route::currentRouteName())) : ?>";
});
Blade::directive('endrouteis', function ($expression) {
return '<?php endif; ?>';
});
@routeis('home')
// Your stuff here
@endrouteis
Example :2
Blade::directive('routeisnot', function ($expression) {
return "<?php if (! fnmatch({$expression}, Route::currentRouteName())) : ?>";
});
Blade::directive('endrouteisnot', function ($expression) {
return '<?php endif; ?>';
});
@routeisnot('home')
// Your stuff here
@endrouteisnot
php artisan make:provider BladeServiceProvider
register in
config/app.php
Add below to the $providers array.
App\Providers\BladeServiceProvider::class,
Add below code in BladeServiceProvider‘s boot() method.
Blade::directive('routeis', function ($expression) {
return "<?php if (fnmatch({$expression}, Route::currentRouteName())) : ?>";
});
Blade::directive('endrouteis', function ($expression) {
return '<?php endif; ?>';
});
@routeis('home')
// Your stuff here
@endrouteis
Example :2
Blade::directive('routeisnot', function ($expression) {
return "<?php if (! fnmatch({$expression}, Route::currentRouteName())) : ?>";
});
Blade::directive('endrouteisnot', function ($expression) {
return '<?php endif; ?>';
});
@routeisnot('home')
// Your stuff here
@endrouteisnot
Comments
Post a Comment