Created
November 28, 2018 04:34
-
-
Save ManojKiranA/64fa45cefc52a1372a02a1ae2ff331d9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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