Skip to main content

Black Friday 2025! Only until December 1st: coupon FRIDAY25 for 40% off Yearly/Lifetime membership!

Read more here

Azuriom/Azuriom

703 stars
4 code files
View Azuriom/Azuriom on GitHub

app/Policies/CommentPolicy.php

Open in GitHub
use Azuriom\Models\Comment;
use Azuriom\Models\User;
use Illuminate\Auth\Access\HandlesAuthorization;
 
class CommentPolicy
{
use HandlesAuthorization;
 
public function create(User $user): bool
{
return $user->can('comments.create');
}
 
public function delete(User $user, Comment $comment): bool
{
return $user->is($comment->author) || $user->can('comments.delete.other');
}
}

app/Providers/AppServiceProvider.php

Open in GitHub
use Azuriom\Models\User;
use Illuminate\Support\Facades\Gate;
 
class AppServiceProvider extends ServiceProvider
{
// ...
 
public function boot(): void
{
// ...
 
Gate::before(function (User $user, string $ability, array $arguments) {
if ($user->isAdmin()) {
return true;
}
 
if (empty($arguments)) {
return $user->role->hasRawPermission($ability);
}
});
}
}

app/Http/Controllers/PostCommentController.php

Open in GitHub
class PostCommentController extends Controller
{
public function __construct()
{
$this->authorizeResource(Comment::class);
}
 
// ...
}

app/Http/Controllers/Controller.php

Open in GitHub
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Routing\Controller as BaseController;
 
abstract class Controller extends BaseController
{
use AuthorizesRequests;
use ValidatesRequests;
}

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.