#laravel

Composable seeders in Laravel with callOnce

Laravel 9 is fresh out the door, and it contains a small contribution of mine: a new callOnce method for database seeders.

Read more


#laravel #blade

Laravel Blade & View Models

An overview on view models in Laravel

Read more


#mysql #laravel

Using MySQL `order by` while keeping one value at the end

The other day I needed to sort a dataset in MySQL and ensure one value was always at the end. I never fully understood how order by works, so I did some research on how to solve my problem and how order by behaves.

Read more


#laravel #eloquent

Eloquent findOrFail caveats

I use Model::findOrFail a lot in Laravel. Recently, I realized it’s not always the best option.

Read more


#laravel #php

Use Blink to execute something once and only once

Our Blink package is marketed as a caching solution to memoize data for the duration of a web request. Recently, we came upon another use case for the package: to execute something once and only once.

Read more


#laravel #web-fonts #performance #privacy

Introducing Laravel Google Fonts

Today, we’re launching a new Spatie package: Laravel Google Fonts. I’ve written about Google Fonts before. It’s a great font catalog, but the service has it’s downsides. First, fonts are hosted on a different domain than your app, so the browser needs to do an additional DNS lookup. Second, it’s Google. Privacy-minded visitors might not appreciate the trip to Silicon Valley.

Read more


#laravel #eloquent / timacdonald.me

Tim MacDonald on HasOne relationships in Laravel

I’ve used HasOne relationships for 1:1 relationships, but those are rare. I haven’t considered using them to scope down relationships, like having one default payment method in a set of n methods.

<?php
 
class User extends Model
{
public function paymentMethods(): HasMany
{
return $this->hasMany(PaymentMethod::class);
}
 
public function defaultPaymentMethod(): ?HasOne
{
return $this->hasOne(PaymentMethod::class)
->whereDefault();
}
}
 
$user->defaultPaymentMethod;

After reading Tim’s post, I have a feeling there are some places where I needed this but didn’t think of it at the time…


#laravel #vite #frontend #build-tools #inertia.js

Vite with Laravel: Using Inertia.js

How to set up Inertia.js in Vite with Laravel.

Read more


#laravel #vite #frontend #build-tools #typescript

Vite with Laravel: Using TypeScript

How to set up TypeScript in Vite with Laravel.

Read more


#laravel #vite #frontend #build-tools #react

Vite with Laravel: Using React

How to set up React in Vite with Laravel.

Read more