https://tim.macdonald.au/feed.xml2023-12-06T23:13:22+00:00Tim MacDonaldDeveloping engaging and performant web applications with Laravel and PHP. Love building for the web.Tim MacDonaldhttps://twitter.com/timacdonald87https://tim.macdonald.au/images/profile.pnghttps://tim.macdonald.au/images/pages/fallback.pnghttps://tim.macdonald.au/single-use-testsSingle-use Tests2023-10-08T09:31:34+11:002023-10-08T10:03:01+11:00Tests I write are usually written in Pest or Jest. I also usually commit them to a code repository - but not all automated tests should be committed. I wrote, what I consider to be an automated test, that was a single-use test. It served it's purpose and it'll forever be in my heart, but not in my repository.the full article]]>https://tim.macdonald.au/fast-database-queries-are-not-always-betterFast database queries are not always better2023-08-24T10:12:59+10:002023-09-10T14:30:54+10:00You probably think fast database queries are good. You also probably think slow database queries are bad. On top of all of these "thinks" you have about database queries - there is a certain Laravel method that, if you’ve seen it, you probably think you understand…but there is a chance you don’t.the full article]]>https://tim.macdonald.au/unique-jobs-and-reserving-resources-on-the-queueUnique jobs and reserving resources on the queue2022-11-21T09:38:49+11:002022-11-21T16:17:55+11:00This post covers some interesting features of Laravel's queueing system. Forcing unique jobs and reserving resources across different job types.the full article]]>https://tim.macdonald.au/introducing-lazy-loading-prevention-into-an-existing-laravel-applicationIntroducing lazy loading prevention into an existing application2021-09-18T21:06:52+10:002023-11-05T15:21:26+11:00Laravel's new lazy loading prevention is fantastic, but depending on the size of your system might be hard to introduce. Here is an approach you might like to try out.the full article]]>https://tim.macdonald.au/git-rebase-a-love-storyGit rebase: A love story2021-07-29T15:03:05+10:002021-07-29T16:32:41+10:00A (not so lightning) talk about git rebase and the things it enables.the full article]]>https://tim.macdonald.au/would-you-like-a-fry-with-that-using-a-has-one-over-a-has-many-relationship-in-laravelWould you like fry with that? Using a HasOne over a HasMany relationship in Laravel2021-03-14T14:12:42+11:002021-07-29T11:33:20+10:00When you are working with a one-to-many relationship, it is sometimes the case that a particular instance on the "many" side of the relationship is flagged as unique and important to your system in some way.the full article]]>https://tim.macdonald.au/follow-the-eloquent-road-laracon-talkFollow the Eloquent road2021-02-22T09:49:20+11:002023-11-05T15:21:26+11:00Conference talk given at the 2020 LaraconUS / Online conference. Come for a journey as I show you down the path I've taken along the Eloquent road.the full article]]>https://tim.macdonald.au/using-laravels-policies-route-model-binding-without-eloquentUsing Laravel's Policies and Route Model Binding without Eloquent2020-10-16T09:24:48+11:002023-09-10T14:30:54+10:00I always thought Laravel's Policies and Route Model Binding were only able to be used with Eloquent models. Turns out I was wrongthe full article]]>https://tim.macdonald.au/gracefully-deprecating-foreign-keys-in-eloquentGracefully deprecating foreign keys for a polymorphic relationship2020-10-10T17:29:52+11:002023-09-10T14:30:54+10:00A "note to self" on how to best handle moving from a classic foreign key constrained relationship, to a polymorphic relationship in Eloquent, without impacting the end user.the full article]]>https://tim.macdonald.au/avoid-false-positives-by-utiliting-magic-values-in-your-testsAvoid false positives by utiliting magic values in your tests2020-06-08T12:00:00+10:002021-07-29T16:18:06+10:00It can be very hard to spot a false positive within a test. So how do you avoid them?the full article]]>https://tim.macdonald.au/sharing-php-cs-fixer-rules-across-projects-and-teamsSharing PHP-CS-Fixer rules across projects and teams2020-04-29T01:00:00+10:002021-07-09T13:08:17+10:00This tutorial will show you how you can setup a repo that contains all your rules, and easily share them with others.the full article]]>https://tim.macdonald.au/rethinking-laravels-middleware-argument-apiRethinking Laravel's middleware argument API2020-04-16T10:00:00+10:002021-07-09T13:08:17+10:00String concatenation is the current way we can pass arguments to Laravel middleware - but what if there was another waythe full article]]>https://tim.macdonald.au/query-scopes-meet-action-scopesQuery scopes, meet action scopes2019-10-12T10:00:00+11:002021-07-09T13:08:17+10:00Action scopes are...well...just query scopes really, but instead of filtering they take an action. It's just a random name I've given them to differentiate them from regular filtering based query scopes in my projects.the full article]]>https://tim.macdonald.au/the-case-laravel-testcaseThe case of the Laravel TestCase2019-06-28T14:00:00+10:002023-09-19T13:35:19+10:00Deep diving the Laravel TestCase and pushing it to the limit, and yea...that's the title I went with 🕵️♂️the full article]]>https://tim.macdonald.au/dedicated-eloquent-model-query-buildersDedicated query builders for Eloquent models2019-04-27T11:11:00+10:002021-07-09T13:08:17+10:00As my current project grew, so did my models. In a hunt for thinner models, I realised it was possible to extract model scopes to a dedicated query builder class. I'll show you how to do this, and a few things to keep in mind if you implement this refactor.the full article]]>https://tim.macdonald.au/performance-monitoring-laravel-forge-deployed-applicationSimple performance monitoring a Laravel Forge deployed application2019-02-11T09:00:00+11:002021-07-29T11:33:20+10:00Monitoring your web application's performance is key to ensuring you provide a good experience for your users. Here is a tip to help you see where your app is slow on a Laravel Forge deployed server.the full article]]>https://tim.macdonald.au/php-be-all-like-that-nonexistent-class-be-coolPHP be all like: that nonexistent class be cool2019-01-23T20:00:00+11:002021-07-09T13:08:17+10:00There are certain scenarios where PHP does not check or error if a class you reference does not exist. These are their stories. *dun-dun*the full article]]>https://tim.macdonald.au/tips-speed-up-your-phpunit-testsTips to speed up your PHPUnit tests2019-01-09T01:00:00+11:002021-07-09T13:08:17+10:00Having a fast test suite can be just as important as having a fast application. Here are some ways to make your test suite run faster.the full article]]>https://tim.macdonald.au/global-application-settingsGlobal application settings2018-11-28T01:00:00+11:002021-07-09T13:08:17+10:00In applications it is often useful to have a way to store some global settings. This post outlines my approach using a Spatie package to manage the values instead of Eloquent.the full article]]>https://tim.macdonald.au/giving-collections-a-voiceGiving collections a voice2018-11-26T15:04:53+11:002023-11-05T15:21:26+11:00Laravel collections have become an essential part of my codebases and I couldn't imagine working without them. I have found giving collections the voice of the problem domain makes for a much nicer API when compared to the generic collection methods.the full article]]>https://tim.macdonald.au/my-feature-test-suite-setupMy feature test suite setup2018-11-11T12:00:00+11:002023-09-19T13:35:19+10:00I do love a good feature test suite. I especially like them to be fast and, most importantly, trustworthy! As my approach has matured, and become stable, I thought I'd share how I go about setting things up.the full article]]>https://tim.macdonald.au/overring-laravel-mix-during-testing-in-5-8Overriding Laravel Mix during testing in 5.82018-11-04T12:00:00+11:002023-09-19T13:35:19+10:00Laravel's global mix helper function can be replaced during testing in Laravel 5.8. Here is why, and how, you might want to do this.the full article]]>https://tim.macdonald.au/loading-eloquent-relationship-countsLoading Eloquent relationship counts2018-11-01T12:00:00+11:002021-07-09T13:08:17+10:00There are several ways to load relationship counts on eloquent models. I'm going to explore the options and introduce you to a new one.the full article]]>https://tim.macdonald.au/versatile-response-objects-laravelVersatile response objects in Laravel2018-05-11T12:00:00+10:002021-07-09T13:08:17+10:00I've found that introducing dedicated response objects that can handle multiple response formats is a really nice pattern to cleanup my controllersthe full article]]>https://tim.macdonald.au/laravel-cashier-helping-handLaravel Cashier: a helping hand2018-05-04T12:00:00+10:002021-07-09T13:08:17+10:00If you are creating a Laravel app with subscriptions via Stripe - Laravel Cashier might just be the helping hand you were looking for.the full article]]>https://tim.macdonald.au/backup-multiple-sites-frameworks-laravel-backupBackup multiple sites and frameworks with Laravel Backup2017-10-31T12:00:00+11:002021-07-29T11:33:20+10:00Using Spatie's Laravel Backup package you can backup several sites on a server from a single app install, including Laravel apps and WordPress sites.the full article]]>https://tim.macdonald.au/foreign-key-validation-ruleForeign key validation rule2017-04-30T13:27:00+10:002021-07-09T13:08:17+10:00A foreign key validation rule for the Laravel Validator that helps wrap up the 'exists' rule with a bit of syntactic sugar. Probably not fantastic to work with in the traditional fashion, but using the rule builder package...it looks gooooood!the full article]]>https://tim.macdonald.au/enforcing-valid-data-access-from-form-request-objectEnforcing valid data access from a form request object2017-04-10T12:00:00+10:002021-07-09T13:08:17+10:00A little trick I have been implementing recently to ensure that data accessed from a Laravel request object has first been validated.the full article]]>https://tim.macdonald.au/writing-a-zero-downtime-deployment-scriptWriting a zero downtime deployment script2017-03-28T12:00:00+11:002021-07-29T11:33:20+10:00Having never written a shell script before, I thought I'd try and level up my dev skills by writing a simple deployment script for my website and my clients websites. The outcome: FlipIt™the full article]]>https://tim.macdonald.au/fluent-validation-rules-for-laravelFluent validation rules for Laravel2016-12-31T23:58:00+11:002021-07-09T13:08:17+10:00Laravel validation rules are great, but wouldn't it be awesome if there was a fluent interface for all the rules.the full article]]>https://tim.macdonald.au/being-a-developer-in-regional-australiaBeing a developer in regional Australia2016-12-30T14:49:00+11:002021-07-09T13:08:17+10:00If you're in the Riverina and wanna meet up to discuss all things software - join our local developer Meetup.the full article]]>