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 models. <?php namespace App; use Illuminate\Database\Eloqu…

  • 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 handle most of this. First you would create a policy for yo…

  • 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 other restrictions such as an "active" state. Since…

  • 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 complex date handling. I needed to find dates up to the end of the…

  • 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 posts are stored as Markdown, more specifically the standar…

  • 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 information is sent to the server. When making a POST reque…

  • Custom Laravel disks & 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 storage solution such as Amazon S3. Out of the box, Laravel a…