Blog post in the category PHP

  • Laravel global scope ambiguous issue

    I came across a small edge-case when using Laravel's Global Scopes after following the example in the documentation. I created an "Active" scope, which can be applied to multiple m…

  • Laravel authorisation with policies and requests

    Laravel comes with a few tools which help you manage authorisation and restrict how different users interact with your application. The Laravel documentation for Authorisation covers how you…

  • Laravel route model binding and global scopes

    I have been using Laravel's Global Scopes in a recent project. Global scopes are a great way to ensure you're only returning the data you need, especially if you're using soft deleting or ot…

  • PHP, Carbon and Dates

    It was the end of the month and another date bug raised its head. In my Laravel application, I make use of the dependency Carbon, which adds syntactic sugar to help manage notoriously comple…

  • Spotify and YouTube Extensions for CommonMark

    In a recent blog post, I wanted to use the Spotify embed code, so I could easily showcase the music about the bands I was talking about. However, I stumbled across a massive problem. My blog…

  • Checkboxes; Hidden Input and Laravel Request Solutions

    Checkboxes are an HTML element that allows you to define a simple on/off piece of information. However, developers often stumble across an issue where if the checkbox is not checked, then no…

  • Custom Laravel Disks and Environment-based Filesystems

    Laravel provides a flexible way of using different "disks" or filesystems to store files. This means you can store files locally in a path relative to your code or using a remote s…

  • LongRunning PHPUnit Extension

    I was running a test suite and noticed that a couple of the tests were stalling. I didn't know which were running slow, so I investigated how I can log which tasks were taking too long to ru…

  • addIf for Laravel Collections

    I wanted to add an item to a Laravel Collection, based on a truthy condition. In the script, I quickly jumped for the basic if syntax, but then wondered if there was a nicer way. if ($condit…

  • Testing Laravel’s Invokable Rules with PHPUnit

    I have previously been writing custom Laravel validation rules with explicit passes() and message() methods. However, since Laravel 9, the preferred method is now a little different. The doc…