Eloquent findOrFail caveats
I use Model::findOrFail
a lot in Laravel. Recently, I realized it's not always the best option.
I use Model::findOrFail
a lot in Laravel. Recently, I realized it's not always the best option.
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.
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.
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…
2021-03-29 #laravel #vite-with-laravel #frontend #build-tools
How to set up Inertia.js in Vite with Laravel.
2021-03-25 #laravel #vite-with-laravel #frontend #build-tools #react
How to set up React in Vite with Laravel.
2021-03-25 #laravel #vite-with-laravel #frontend #build-tools #typescript
How to set up TypeScript in Vite with Laravel.
2021-03-22 #laravel #vite-with-laravel #frontend #build-tools #blade
How to set up Tailwind CSS in Vite with Laravel.
2021-03-22 #laravel #vite-with-laravel #frontend #build-tools #tailwind
How to set up Tailwind CSS in 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.
2021-03-22 #laravel #vite-with-laravel #frontend #build-tools #vue
How to set up Vue.js in Vite with Laravel.
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.
2020-09-29 #laravel #typescript
My colleague Ruben released a new Spatie package to generate type declarations in TypeScript from a Laravel application.
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.
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.