2021-11-23 #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


2021-07-22 #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


2021-06-23 #laravel #webfonts #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


2021-03-30 #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…


2021-03-29 #laravel #vite-with-laravel #frontend #build-tools

Vite with Laravel: Using Inertia.js

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

Read more


2021-03-25 #laravel #vite-with-laravel #frontend #build-tools #react

Vite with Laravel: Using React

How to set up React in Vite with Laravel.

Read more


2021-03-25 #laravel #vite-with-laravel #frontend #build-tools #typescript

Vite with Laravel: Using TypeScript

How to set up TypeScript in Vite with Laravel.

Read more


2021-03-22 #laravel #vite-with-laravel #frontend #build-tools #blade

Vite with Laravel: Auto-refresh Blade views

How to set up Tailwind CSS in Vite with Laravel.

Read more


2021-03-22 #laravel #vite-with-laravel #frontend #build-tools #tailwind

Vite with Laravel: Using Tailwind CSS

How to set up Tailwind CSS in Vite with Laravel.

Read more


2021-03-22 #laravel #vite-with-laravel #frontend #build-tools

Vite with Laravel

I've had an eye on Vite for a while. With a stable release out the door (2.0, as 1.0 never left the release candidate stage) it seemed like a good time to give it a shot.

Vite is a frontend build tool like webpack. Instead of bundling development assets, Vite serves native ES modules transpiled with esbuild from the dev server. This means there's a lot less bundling to do, and results in a very fast developer experience. For production builds, Vite uses Rollup to bundle the assets.

Read more


2021-03-22 #laravel #vite-with-laravel #frontend #build-tools #vue

Vite with Laravel: Using Vue.js

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

Read more


2020-10-01 #spatie #laravel #php #javascript

The revamped Spatie guidelines

I created the original Spatie guidelines site three years ago. Last month, we consolidated a few of our subsites to our main spatie.be site, including the guidelines.

Read more


2020-09-29 #laravel #typescript

Laravel Typescript Transformer

My colleague Ruben released a new Spatie package to generate type declarations in TypeScript from a Laravel application.

Read more


2020-06-03 #laravel

Middleware as a Laravel service provider

When you need to set up a service in a Laravel app, service providers are generally the place to be. But, there's one problem with service providers: they're global. This usually doesn't matter, but in multi-section apps this can be problematic.

Read more


2019-11-05 #laravel

Handling authorization in a Laravel and Inertia application

I last blogged about handling routes in a Laravel and Inertia app. The premise was that we don't have access to Laravel's URL generator functions with Inertia, so we need to pass our application's routes down differently.

The same problem exists with authorization: we don't have access to the can helper and other Gate methods. Here's a short post about dealing with authorization on the frontend.

Read more