Laravel Task API / Versioned API learning project / 2024
Adding task ownership to a versioned Laravel API.
The v2 coursework API combines Sanctum, user-owned task queries and Laravel policies for its main create, read, update and delete actions.
- ROLE
- API implementation / coursework
- STATE OF THE BUILD
- Study
- RECORD UPDATED
THE WORK
The project.
Version two of this task API makes ownership part of its main request path. Sanctum identifies the caller, task listing and creation use that user's relationship, and policies compare the user with the owner before reading, changing or deleting an individual task. Request classes validate input and JSON resources format the response. The study also exposes an unfinished part of the design: completion uses a separate unchecked handler, and the older public API routes remain defined.
IMPLEMENTATION
Design choices.
- Creating through the user's task relationship assigns ownership without accepting an owner selected by the caller.
- Policies make the record-level decision explicit at each main CRUD action. A separate action such as completion still needs to invoke the same rule; sharing a route group doesn't do that for it.
- TaskResource keeps task formatting in one place, so the controllers can return the same representation after different operations.
- Versioning leaves two reachable sets of behavior in the source. Reviewing only v2 would miss the access allowed by the earlier public routes.
HOW IT FITS TOGETHER
Architecture.
- The v2 route group requires Sanctum authentication. Its task controller lists records through the current user and creates new tasks through the same relationship, deriving the owner from the request's identity.
- For an individual task, the controller calls a policy before returning, updating or deleting it. StoreTaskRequest and UpdateTaskRequest supply validated fields; TaskResource supplies a consistent JSON representation.
- Completion takes a different path: its handler saves is_completed without the CRUD controller's policy check. The public v1 routes are still present too, so the newer checks don't describe every route in the service.
- The related Vue Task Client contains matching task and completion calls. That connection is supported by the interfaces in source, not a verified running client and server session.
MADE WITH
PHP · Laravel 11 · Sanctum · Eloquent · JSON resources
ACCESS & INPUT
Security controls.
- The main v2 task controller uses the authenticated user's relationship for listing and creation. Individual read, update and delete policies compare the current user's ID with the task owner.
- The separate completion action doesn't apply that ownership check, and v1 remains public in the route definitions. The API cannot yet be described as consistently protected.
CHECKS & RESULTS
What was checked.
A source review shows what the code does. It is not a fresh test of the running app.
Code and development records reviewedReviewed
The code, tests and available development records were checked. Reported test results keep their original scope. No fresh app or live deployment check was run for this write-up.
- Scope of this check
- Code review, not a fresh run of the app
NEXT
Still to work through.
The next step is to make authorization consistent across versions and actions, then test requests against another user's task ID. This remains a coursework API; the source review didn't exercise those requests or verify deployment.