Same posts, different eyes.
Write once who can see and edit which rows. Your lists, Edit buttons and search follow.
Ada is an admin: she sees and edits every post.
- Q4 launch plan: found
- Launch day checklist: found
- Globex launch recap: found
- Q4 launch plancan edit
- Pricing page copycan edit
- Launch day checklistcan edit
- Release notes 2.4can edit
- Brand refresh briefcan edit
- Globex launch recapcan edit
composer require lomkit/laravel-access-controlWhy one file
Two rules drift. One control cannot.
Without it, a policy answers “may Sam open this post?” and a scope answers “which posts does Sam list?”. Written twice, they disagree.
Before
Sam may view his own posts only.
His list never shows post 2. The policy still opens it by its URL, because it belongs to his company. No test fails.
After
The policy, the lists and the search read the same file.
Behind $user->can(), the controlled() scope and controlled searches. And a test proves they agree:
$this->assertControlAgrees(PostControl::class, $sam, Post::uncontrolled()->get());
laravel-rest-api
Your API follows too.
With laravel-rest-api 3.6 or later, there is nothing to wire: one route line, and each user gets their own rows.
- Ada
POST /api/posts/search
→ posts 1, 2, 3, 4, 5, 6 - Marc
POST /api/posts/search
→ posts 1, 2, 3, 4 - Lea
POST /api/posts/search
→ posts 1, 2, 3, 4 - Guest
POST /api/posts/search
→ no row