laravel

  • Single-server scheduling and the cron that ran three times

    Three application servers each running the same crontab means every scheduled task runs three times, and the invoice job discovers this before you do. The lock is a…

  • Model events do not fire on a mass update

    An observer that keeps a search index in step works perfectly until somebody writes a query builder update, at which point the rows change and nothing notices. This…

  • Laravel 5.6 and logging you can configure

    Logging moved into a config file, and stacks are why it matters — a different format per destination, decided without touching a service provider.

  • The service provider you always end up writing

    Every service eventually needs the same provider: bind the interfaces, register the client with its credentials, and set up whatever the framework does not do on its own.…

  • The dump-server keeps var_dump out of the response

    Dumping from inside a JSON endpoint, a queue worker or a middleware corrupts the output you were trying to inspect, so the debugging tool destroys the thing being…

  • Collections lazily, with chunk and cursor

    Model::all() on a table with four hundred thousand rows hydrates four hundred thousand objects and then the process dies, having done nothing. chunkById rather than chunk is the…

  • A macro is how you extend a framework class without extending it

    Adding a method to a collection or a response means subclassing, and subclassing a framework class means every place that constructs one has to know about your subclass.…

  • The Responsable interface removes a controller branch

    A controller returning either a view or JSON depending on the request ends up with the same conditional in every action, and the decision has nothing to do…

  • The service container resolves callables too

    The container is usually described in terms of constructor injection, so a method needing one dependency for one call ends up either taking it in the constructor or…

  • The 5.5 exception that renders itself

    Custom exceptions have always had to be translated into a response somewhere in the handler, which turns one file into a growing chain of instanceof checks. 5.5 lets…