laravel

  • Laravel 5.3 notifications unified the channels

    Sending the same event by email, SMS and a database record meant three call sites and three formats to keep in step. 5.3 makes the notification one class…

  • Laravel 5.2 middleware groups replaced the kernel list

    Before 5.2 the HTTP kernel had one global middleware stack, so anything needed by web routes also ran for API routes — sessions, CSRF verification and cookie encryption…

  • artisan tinker is a REPL with the application booted

    Checking what a relation actually returns usually means writing a throwaway route, hitting it, and deleting it — or adding a dd() somewhere and reloading. Both are slower…

  • The container binds interfaces, not only concrete classes

    The container resolves concrete classes automatically, which is convenient enough that most code type-hints the concrete class and the abstraction never happens. Contextual binding is the part worth…

  • The N+1 queries you did not write

    1,400 queries on a page showing 40 rows. Eager loading, the difference between with() and load(), and the accessor that no eager load can fix.

  • Query scopes are where the repeated where() clauses go

    The same three conditions appear in nine controllers, and when the definition of “active” changes there are nine places to edit and one that gets missed. The naming…

  • chunkById is the safe one when the loop mutates rows

    chunk() paginates with OFFSET, so if the loop body changes whether a row still matches the query, the offset for the next page has shifted and rows get…

  • Model events fire on the model, not on the query builder

    Eloquent fires saving, created, deleted and the rest when a model instance is saved. A mass update or delete goes straight to the query builder and fires nothing…

  • Implicit route model binding removes the find()

    Every controller method that takes an id begins the same way: find the record, check it exists, abort with a 404. Multiply that by every route and it…

  • Restructuring an application for Laravel 5

    4.2 to 5.0 is not an upgrade, it is a relocation. Moving an application through it in an order that keeps it booting at every step.