Skip to content

Instantly share code, notes, and snippets.

View nataliaconde's full-sized avatar
🏠
Working from home

Natália Condê nataliaconde

🏠
Working from home
  • SJC - SP, BR
View GitHub Profile
<?php
namespace App\Policies;
use App\Models\Post;
use App\Models\User;
class PostPolicy
use Illuminate\Support\Facades\Gate;
Gate::guessPolicyNamesUsing(function (string $modelClass) {
// Provide the name of the model’s policy class…
});
<?php
namespace App\Providers;
use App\Models\Post;
use App\Policies\PostPolicy;
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
if (Gate::any(['can-post', 'delete-post'], $post)) {
// The user is authorized to update and delete the post…
}
if (Gate::none(['can-post', 'delete-post'], $post)) {
// The user cannot update or delete the post…
if (Gate::forUser($user)->allows('can-post', $post)) {
// The user is authorized to update the post…
}
if (Gate::forUser($user)->denies('can-post', $post)) {
// The user cannot update the post…
use App\Policies\PostPolicy;
use Illuminate\Support\Facades\Gate;
/**
* Register all authorization and authentication services.
*/
use App\Models\Post;
use App\Models\User;
use Illuminate\Support\Facades\Gate;
/**
* Register all authorization and authentication services.
class PostPolicy
{
public function update(User $user)
{
return $ $user->role == ‘admin’;
Gate::define('can_post', function($user) {
return $user->role == 'admin';
});
#.dockerignore
.idea/
.git/
/node_modules
/.next/
/out/
/build