Skip to content

Instantly share code, notes, and snippets.

@albofish
Created September 2, 2016 10:48
Show Gist options
  • Save albofish/b61653179ee2a7d565eca346d026188f to your computer and use it in GitHub Desktop.
Save albofish/b61653179ee2a7d565eca346d026188f to your computer and use it in GitHub Desktop.
Entrust Laravel 5.3 Blade syntax fix
  1. Create a new folder in the root application folder; app/Extensions/EntrustFix/
  2. Copy EntrustFixFacade.php and EntrustFixServiceProvider.php in to app/Extensions/EntrustFix/
  3. Add App\Extensions\EntrustFix\EntrustFixServiceProvider::class,to your providers in config/app.php
  4. Update config/app.php aliases to;
//'Entrust' => Zizaco\Entrust\EntrustFacade::class,
'Entrust' => \App\Extensions\EntrustFix\EntrustFixFacade::class,
<?php namespace App\Extensions\EntrustFix;
use Zizaco\Entrust\EntrustFacade;
class EntrustFixFacade extends EntrustFacade
{
//
}
<?php namespace App\Extensions\EntrustFix;
use Zizaco\Entrust\EntrustServiceProvider;
class EntrustFixServiceProvider extends EntrustServiceProvider
{
/**
* Indicates if loading of the provider is deferred.
*
* @var bool
*/
protected $defer = false;
/**
* Bootstrap the application events.
*
* @return void
*/
public function boot()
{
// Publish config files
$this->publishes([
__DIR__ . '/../config/config.php' => config_path('entrust.php'),
]);
// Register commands
$this->commands('command.entrust.migration');
// Register blade directives
$this->bladeDirectivesFixed();
}
/**
* Register the blade directives
*
* @return void
*/
private function bladeDirectivesFixed()
{
// Call to Entrust::hasRole
\Blade::directive('role', function ($expression) {
return "<?php if (\\Entrust::hasRole({$expression})) : ?>";
});
\Blade::directive('endrole', function ($expression) {
return "<?php endif; // Entrust::hasRole ?>";
});
// Call to Entrust::can
\Blade::directive('permission', function ($expression) {
return "<?php if (\\Entrust::can({$expression})) : ?>";
});
\Blade::directive('endpermission', function ($expression) {
return "<?php endif; // Entrust::can ?>";
});
// Call to Entrust::ability
\Blade::directive('ability', function ($expression) {
return "<?php if (\\Entrust::ability({$expression})) : ?>";
});
\Blade::directive('endability', function ($expression) {
return "<?php endif; // Entrust::ability ?>";
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment