Created
October 24, 2017 14:27
-
-
Save dieggop/5a2e63c74da230a67f9052099fbfacb1 to your computer and use it in GitHub Desktop.
AuthServiceProvider
This file contains 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
public function index() | |
{ | |
if (Gate::forUser(Auth::guard('admin_user')->user())->denies('listar-conteudos')) { | |
abort(403,'Não pode listar conteudos'); | |
} | |
$conteudos = $this->conteudos->orderBy('id', 'desc')->paginate(10); | |
This file contains 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 Unita\Policies; | |
use Auth; | |
use Illuminate\Auth\Access\HandlesAuthorization; | |
use Unita\AdminUser; | |
use Unita\Conteudo; | |
class ConteudoPolicy | |
{ | |
use HandlesAuthorization; | |
public function before($user, $ability) | |
{ | |
if ($user->isSuperAdmin()) { | |
return true; | |
} | |
} | |
public function listarConteudos($user) { | |
return $user === 1; | |
} | |
} | |
This file contains 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 Unita\Providers; | |
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider; | |
use Illuminate\Support\Facades\Gate; | |
use Unita\Conteudo; | |
use Unita\Policies\ConteudoPolicy; | |
class AuthServiceProvider extends ServiceProvider | |
{ | |
/** | |
* The policy mappings for the application. | |
* | |
* @var array | |
*/ | |
protected $policies = [ | |
'Unita\Model' => 'Unita\Policies\ModelPolicy', | |
'Unita\Conteudo' => 'Unita\Policies\ConteudoPolicy', | |
]; | |
/** | |
* Register any authentication / authorization services. | |
* | |
* @return void | |
*/ | |
public function boot() | |
{ | |
$this->registerPolicies(); | |
Gate::define('listar-conteudos', 'ConteudoPolicy@listarConteudos'); | |
// | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment