app/Providers/AuthServiceProvider.php
/**
     * Register any authentication / authorization services.
     *
     * @return void
     */
Register any authentication / authorization services.
@return void
Register any authentication / authorization services . @return void
public function boot()
    {
        $this->registerPolicies();
        Gate::define(Actions::CREATE, function (Utilisateur $user, Collection $serviceAllow){
	        foreach ($serviceAllow as $service)
	        {
		        if ($user->employe->service->code == $service){
        		    return true;
	            }
	        }
	        return false;
        });
        Gate::define(Actions::UPDATE, function (Utilisateur $user, Collection $serviceAllow){
	        foreach ($serviceAllow as $service)
	        {
		        if ($user->employe->service->code == $service){
	                return true;
		        }
	        }
	        return false;
        });
        Gate::define(Actions::READ, function (Utilisateur $user, Collection $serviceAllow){
        	foreach ($serviceAllow as $service)
	        {
		        if($user->employe->service->code == $service){
			        return true;
		        }
	        }
	        return false;
        });
        Gate::define(Actions::DELETE, function (Utilisateur $user, Collection $serviceAllow){
	        foreach ($serviceAllow as $service)
	        {
		        if($user->employe->service->code == $service){
        		    return true;
	            }
	        }
	        return false;
        });
    }
public function boot ( ) { $ this -> registerPolicies ( ) ; Gate :: define ( Actions :: CREATE , function ( Utilisateur $ user , Collection $ serviceAllow ) { foreach ( $ serviceAllow as $ service ) { if ( $ user -> employe -> service -> code == $ service ) { return true ; } } return false ; } ) ; Gate :: define ( Actions :: UPDATE , function ( Utilisateur $ user , Collection $ serviceAllow ) { foreach ( $ serviceAllow as $ service ) { if ( $ user -> employe -> service -> code == $ service ) { return true ; } } return false ; } ) ; Gate :: define ( Actions :: READ , function ( Utilisateur $ user , Collection $ serviceAllow ) { foreach ( $ serviceAllow as $ service ) { if ( $ user -> employe -> service -> code == $ service ) { return true ; } } return false ; } ) ; Gate :: define ( Actions :: DELETE , function ( Utilisateur $ user , Collection $ serviceAllow ) { foreach ( $ serviceAllow as $ service ) { if ( $ user -> employe -> service -> code == $ service ) { return true ; } } return false ; } ) ; }
Register any authentication / authorization services.
Register any authentication / authorization services .
/*
        Gate::before(function (Utilisateur $user, Collection $serviceAllow){
	        if($user->employe->service->code == Service::INFORMATIQUE){
		        return true;
	        }
        });
*/