Laravel Policies and Gates: authorize actions in controllers
PHP Dasun Kalupahana 41 views
<?php
// php artisan make:policy PostPolicy --model=Post
public function update(User $user, Post $post): bool
{
return $user->id === $post->user_id;
}
// Controller
use Illuminate\Support\Facades\Gate;
public function update(Request $request, Post $post)
{
Gate::authorize('update', $post);
// ...
}
Keeps permission rules in one policy class instead of scattering if checks. Gate::authorize throws a 403 when the check fails.
Learn more on the blog
MySQL
PostgreSQL vs MySQL Performance: Real Benchmarks Compared
Last updated: 7 November 2026. See the update log at the end."Which...
8 min read
Laravel
Secure a Laravel App Before Production: Tested Checklist
Last updated: 8 November 2026. See the update log at the end.Laravel...
12 min read
PHP
How to Detect and Fix PHP Memory Leaks
Last updated: 5 November 2026. See the update log at the end.In...
9 min read