Laravel Blade & View Models

2022-01-10 #laravel #blade

An overview on view models in Laravel

Read more


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

2021-12-16 #mysql #laravel

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


Eloquent findOrFail caveats

2021-11-23 #laravel #eloquent

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

Read more


Use Blink to execute something once and only once

2021-07-22 #laravel #php

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


Introducing Laravel Google Fonts

2021-06-23 #laravel #webfonts #performance #privacy

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


Tim MacDonald on HasOne relationships in Laravel

2021-03-30 #laravel #eloquent / timacdonald.me

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…


Vite with Laravel: Using Inertia.js

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

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

Read more


Vite with Laravel: Using React

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

How to set up React in Vite with Laravel.

Read more


Vite with Laravel: Using TypeScript

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

How to set up TypeScript in Vite with Laravel.

Read more


Vite with Laravel: Auto-refresh Blade views

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

How to set up Tailwind CSS in Vite with Laravel.

Read more


Vite with Laravel: Using Tailwind CSS

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

How to set up Tailwind CSS in Vite with Laravel.

Read more


Vite with Laravel

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

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


Vite with Laravel: Using Vue.js

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

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

Read more


The revamped Spatie guidelines

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

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


Laravel Typescript Transformer

2020-09-29 #laravel #typescript

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

Read more