Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

Natália Condê nataliaconde

🏠
Working from home
  • SJC - SP, BR
View GitHub Profile
View authorized-actions.php
<?php
namespace App\Policies;
use App\Models\Post;
use App\Models\User;
class PostPolicy
View registering.php
use Illuminate\Support\Facades\Gate;
Gate::guessPolicyNamesUsing(function (string $modelClass) {
// Provide the name of the model’s policy class…
});
View registerPolicy.php
<?php
namespace App\Providers;
use App\Models\Post;
use App\Policies\PostPolicy;
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
View authorized-users-action.php
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…
View authorized-users.php
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…
View PostPolicy.php
use App\Policies\PostPolicy;
use Illuminate\Support\Facades\Gate;
/**
* Register all authorization and authentication services.
*/
View update-policy.php
use App\Models\Post;
use App\Models\User;
use Illuminate\Support\Facades\Gate;
/**
* Register all authorization and authentication services.
View policy.php
class PostPolicy
{
public function update(User $user)
{
return $ $user->role == ‘admin’;
View gate.php
Gate::define('can_post', function($user) {
return $user->role == 'admin';
});
View .dockerignore
#.dockerignore
.idea/
.git/
/node_modules
/.next/
/out/
/build