Skip to content

Reviewing Ergodnc - What a Clean Laravel API Still Gets Wrong

Code Reviews•
October 12, 2026

Ergodnc (Ergonomic Desk & Coffee, per its README) is the office-rental API Mohamed Said built live on the official Laravel YouTube channel. The repository is themsaid/ergodnc, and this review reads it at commit 42907c0 from 26 November 2021. It runs Laravel 8 (^8.54 in composer.json, 8.63.0 in the lock file) with Sanctum, has nine controllers, five models, four feature test files with 39 tests, and no unit tests. Hosts publish offices, guests reserve them by the day, admins approve new offices.

It is a good codebase by the standards I see applied in most Laravel codebases I review. Controllers are short, output goes through API resources, six of the seven write endpoints have tests, models are unguarded on purpose, and the morph map is enforced. The reason to review it is exactly that it is clean by those standards and still fails the rules that matter once a codebase has to survive years of change.

The rulebook

The audit uses a fixed rulebook, which I call the canon, that I apply to every Laravel codebase I want to keep for the long term. It ignores the project's own conventions. In short: controllers and handlers coordinate, and the model that owns the data owns the rule. Each capability is one vertical slice folder (command, handler, controller, request, resource, event, listener). Each business area is a module that reaches other modules only through interfaces it defines, through events, or through read-only queries by id. Authorization comes from the authenticated user, and the ownership check lives inside the model lookup. The rebuilt code targets Laravel 13.

The five reviews

Each review takes one flow, shows the current code, lists what is wrong with it, and rebuilds it as a slice.

Problems that show up in every flow are listed once below and not repeated in each review.

What Ergodnc gets right

  • Model::unguard() at app/Providers/AppServiceProvider.php:31 turns off mass-assignment protection, which matches the rule that models declare neither $fillable nor $guarded, with validation at the boundary.

  • Relation::enforceMorphMap([...]) at AppServiceProvider.php:33-36 keeps class names out of the images.resource_type column.

  • Every response that carries a body goes through a JsonResource. OfficeResource at app/Http/Resources/OfficeResource.php:19-22 uses whenLoaded for every relation.

  • All five notifications implement ShouldQueue.

  • Six of the seven write endpoints have feature coverage; only DELETE /reservations/{reservation} has none. itMakesReservations at tests/Feature/UserReservationControllerTest.php:163 pins the discount: stays of 28 days or more get the office's monthly discount, so 40 days at 1,000 a day with 10% off comes to 36000. itMarksTheOfficeAsPendingIfDirty at tests/Feature/OfficeControllerTest.php:334 pins the re-approval rule at OfficeController.php:108: changing an office's lat, lng, or price_per_day sends it back to pending approval. The test changes lat and asserts the office is pending again. Those tests are the safety net for every rebuild in the series except cancel and the host reservations listing, which have none.

  • Concurrency on double booking is handled with Cache::lock at app/Http/Controllers/UserReservationController.php:84, which most tutorial APIs I have read skip.

What breaks the rules everywhere

  • Code is grouped by framework type: everything sits under app/Http/Controllers, app/Models, app/Notifications, and app/Policies. OfficeController has five actions and UserReservationController has three, where the canon wants one invokable controller per endpoint.

  • None of the 44 files under app/ opens with declare(strict_types=1);, none of the classes is final, and all nine controllers extend the framework's base Controller.

  • Production code calls facades and helpers instead of taking dependencies through the constructor. Counting files that import each facade across the controllers and the console command: Notification 5, Auth 3, Cache 3, Storage 2, RateLimiter 2, DB 1, Hash 1. The controllers call the request() helper 49 times and auth() 19 times, plus validator(), abort_unless(), throw_if(), and now().

  • Token abilities are checked with nine tokenCan('...') string literals inside the controllers (UserReservationController.php:24, :54, :122; OfficeController.php:65, :98, :131; OfficeImageController.php:18, :39; HostReservationController.php:15). The canon wants ability middleware on the route with a typed constant.

  • Business rules are thrown as validation errors. Eight rules use ValidationException::withMessages (UserReservationController.php:67, :73, :79, :90, :129; OfficeController.php:139; OfficeImageController.php:46, :50; a ninth call at LoginController.php:39 handles bad credentials), so "you cannot reserve your own office" and a malformed date both come back as the same 422.

  • Approval and reservation statuses are integer class constants (app/Models/Office.php:18-19, app/Models/Reservation.php:13-14) instead of enums.

  • No domain event exists. The only mapped event in app/Providers/EventServiceProvider.php:17-21 is the framework's Registered, and every notification is sent inline from a controller.

  • Every route with a parameter uses route-model binding (routes/api.php:29, :31, :32, :35, :36, :41), so the lookup happens before any ownership check can scope it. No route has a name (routes/api.php:17-44). Login and register (routes/api.php:17-18) carry only the global throttle:api limit of 60 requests a minute (app/Http/Kernel.php:44) and no stricter limiter of their own, and /host/reservations has no auth middleware at all (routes/api.php:44), although HostReservationController.php:15 calls a method on auth()->user().

  • The tests use the @test docblock and camelCase names. PHPUnit 9 on Laravel 8 has no #[Test] attribute, so I don't count the docblock against it. What is missing matters more: no test asserts a 401 for a logged-out request, the three cancel conditions at UserReservationController.php:126-132 have no test, and the 28-day discount has one test, the 40-day case at UserReservationControllerTest.php:182, with nothing on the 27-versus-28-day boundary.

The module map

The rebuild splits the app into three modules. App\Offices owns offices, images, tags, and approval. App\Reservations owns reservations, stays, and prices. App\Identity owns the User model, login, and tokens. A Shared folder holds only the QueueName enum.

Today Office::reservations() at app/Models/Office.php:35-38 and Reservation::office() at app/Models/Reservation.php:29-32 tie offices and reservations together, and the office listing filters and counts through that relation at OfficeController.php:31 and :47. The database does not: database/migrations/2021_09_09_124300_create_reservations_table.php:19 declares office_id with foreignId() and no constrained(), so no foreign key exists. After the split, office_id and user_id are plain integer columns with no relation behind them.

When one module needs something from another, it defines an interface in its own Contracts/ folder, and the module that owns the data implements it in Integrations/ and binds it in its service provider:

  • Reservations defines ReservableOffices, which Offices implements in OfficesForReservations, and ReservationContacts, which Identity implements in ContactsForReservations.

  • Offices defines ActiveReservations and OfficeReservations, which Reservations implements in one class, ReservationsForOffices, and OfficeAdmins, which Identity implements in AdminsForOffices.

Notifications go to email addresses through Laravel's on-demand notifications, so neither Offices nor Reservations imports the User model.

Reservations needs the host's id to notify them and to list a host's reservations, so it stores its own copy as reservations.host_user_id, taken from the office at booking time. An office never changes host (OfficeController.php:75 sets user_id once, and the validator has no user_id rule), so nothing has to keep the copy in sync. Existing rows are filled by a one-off BackfillReservationHosts command between two migrations, because a migration must not touch another module's table.

Before, at commit 42907c0, the code is grouped by framework type (the eight stock middleware files are collapsed):

TEXT
app/ Console/ Kernel.php Commands/ SendDueReservationsNotifications.php Exceptions/ Handler.php Http/ Kernel.php Controllers/ Controller.php HostReservationController.php LoginController.php LogoutController.php OfficeController.php OfficeImageController.php RegisterController.php TagController.php UserController.php UserReservationController.php Middleware/ eight stock Laravel middleware Resources/ ImageResource.php OfficeResource.php ReservationResource.php TagResource.php UserResource.php Models/ Image.php Office.php Reservation.php Tag.php User.php Validators/ OfficeValidator.php Notifications/ HostReservationStarting.php NewHostReservation.php NewUserReservation.php OfficePendingApproval.php UserReservationStarting.php Policies/ OfficePolicy.php Providers/ AppServiceProvider.php AuthServiceProvider.php BroadcastServiceProvider.php EventServiceProvider.php RouteServiceProvider.php routes/ api.php

After the rebuild, with the slices the five reviews build:

TEXT
app/ Identity/ IdentityServiceProvider.php Integrations/ AdminsForOffices.php ContactsForReservations.php User/ User.php Offices/ OfficeAbility.php OfficesException.php OfficesServiceProvider.php offices-routes.php Contracts/ ActiveReservations.php OfficeAdmins.php OfficeReservations.php Integrations/ OfficesForReservations.php Files/ OfficeImageFiles.php Image/ Image.php Tag/ Tag.php Office/ Office.php, OfficeFactory.php, OfficeApprovalStatus.php, OfficeDetails.php, OfficeChanges.php, domain exceptions SubmitOffice/ ReviseOffice/ DeleteOffice/ DeleteOfficeImage/ ListOffices/ Reservations/ ReservationAbility.php ReservationsException.php ReservationsServiceProvider.php reservations-routes.php BackfillReservationHosts/ BackfillReservationHosts.php Contracts/ ReservableOffice.php ReservableOffices.php ReservationContacts.php Integrations/ ReservationsForOffices.php Reservation/ Reservation.php, ReservationFactory.php, ReservationStatus.php, ReservationLock.php, Stay.php, StayPrice.php, domain exceptions ReserveOffice/ CancelReservation/ ListGuestReservations/ ListHostReservations/ Shared/ Queue/ QueueName.php bootstrap/ app.php providers.php database/migrations/ 2026_10_12_000001_add_host_user_id_to_reservations_table.php 2026_10_12_000002_make_host_user_id_required_on_reservations_table.php 2026_10_12_000003_convert_reservation_status_to_string.php 2026_10_12_000004_convert_office_approval_status_to_string.php

Each module's service provider loads its route file inside the api middleware group with no URL prefix. The canon says module routes load under the api prefix, but ergodnc serves its API at the root path (app/Providers/RouteServiceProvider.php sets no prefix, and every test uses root paths), and adding the prefix would change every URL the reviews quote.

Open items

  • Ids stay enumerable. Offices, images, and reservations are addressed by their auto-increment primary key (routes/api.php:29-41), which the canon forbids. Switching to ULIDs touches every route, resource, and factory, and none of the flows needs it to make its point.

  • The reviews do not show tests. The existing feature tests assert the old 422s and the old 200 on delete, so each rebuild changes them.

  • SendDueReservationsNotifications at app/Console/Commands/SendDueReservationsNotifications.php is not rebuilt. It calls now() and Notification::send in handle() (lines 47-50) and still has the scaffold description "Command description" at line 25.

  • Login, register, logout, and the tags endpoint are untouched, so their findings above stay open.

  • The image upload, POST /offices/{office}/images at routes/api.php:35, is not rebuilt.