Skip to content

Instantly share code, notes, and snippets.

@dieggop
Created October 24, 2017 14:27
Show Gist options
  • Save dieggop/5a2e63c74da230a67f9052099fbfacb1 to your computer and use it in GitHub Desktop.
Save dieggop/5a2e63c74da230a67f9052099fbfacb1 to your computer and use it in GitHub Desktop.
AuthServiceProvider
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);
<?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;
}
}
<?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