Skip to content

Instantly share code, notes, and snippets.

@ManojKiranA
Created November 28, 2018 04:34
Show Gist options
  • Save ManojKiranA/64fa45cefc52a1372a02a1ae2ff331d9 to your computer and use it in GitHub Desktop.
Save ManojKiranA/64fa45cefc52a1372a02a1ae2ff331d9 to your computer and use it in GitHub Desktop.
<?php
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\Gate;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\Facades\Blade;
use App\Models\Permission;
class PermissionServiceProvider extends ServiceProvider
{
/**
* Bootstrap services.
*
* @return void
*/
public function boot()
{
if (Schema::hasTable('permissions'))
{
Permission::get()->map(function ($permission)
{
Gate::define($permission->name, function ($user) use ($permission)
{
return $user->hasPermission($permission);
});
});
}
Blade::directive('role', function ($role)
{
return "<?php if(Auth::user()->hasRole({$role})): ?>";
});
Blade::directive('endrole', function ($role)
{
return "<?php endif; ?>";
});
}
/**
* Register services.
*
* @return void
*/
public function register()
{
//
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment