Increase performance by using Eloquent's `setRelation` method original
While working on the upcoming Oh Dear redesign, I noticed that list that displays all sites of a team was very slow.
To display that list, a lot of queries were used. With a couple of minor adjustments, I could reduce the number of queries needed to just a single one, solving the performance problem.
In this small blog post, I'd like to share one of the techniques I used.
Join 9,500+ smart developers
Get my monthly newsletter with what I learn from running Spatie, building Oh Dear, and maintaining 300+ open source packages. Practical takes on Laravel, PHP, and AI that you can actually use.
No spam. Unsubscribe anytime. You can also follow me on X.
"Freek publishes a super resourceful and practical newsletter. A must for anyone in the Laravel space"
How the Laravel Login Link package works under the hood
Povilas Korop of Laravel Daily made a cool video on the internals of our spatie/laravel-login-link package.
Why working code is not enough? Write Better Laravel, Part 2
– arunas.dev - submitted by Arunas
You'll learn the difference between "tactical" and "strategic" programming, and why choosing the right approach is important in the long run.
Read more [arunas.dev]
Efficient Pagination Using Deferred Joins
I wonder if Laravel should use this technique by default. It seems to have a major positive impact on performance.
Read more [aaronfrancis.com]
Invokable custom validation rules in Laravel
Povilas demonstrates a nice little features that was recently added to Laravel.
Making sure routes, config and events of your Laravel app are cached in production original
A typical Laravel application will likely have many routes, config files and possibly some events. In your development environment, these routes and config files will be loaded and registered in each request. The performance penalty for this is not too big. In a production environment, you want to…
What is complexity? Write Better Laravel, Part 1
– arunas.dev - submitted by Arunas
Before we learn strategies for better software design, we must understand our enemy - complexity. Let’s define complexity, how to spot it, and what causes it.
Read more [arunas.dev]
Introducing our new Laravel Options package original
When developing web applications, you probably encounter a lot of places where someone needs to select one or more options in a select or multi-select. These select boxes always need a list of options with labels and values.
In one of our projects, we had options being generated in lots of places. Sometimes these lists of options were the same, leading to a lot of code duplication. Even worse, in some cases, different formats were used to output the same options.
That's why we've created a new package called spatie/laravel-options. It will take a resource which can create options such as an enum, a list of models or even a plain array. And will always create a standardized array of options you can use within your frontend application.
Auto-Refresh Livewire Components While Keeping States With Vite
Let's check out how we can improve working with Livewire and Vite together, by using the Vite Livewire Plugin by Fabio Ivona.
Read more [christoph-rumpel.com]
Add comments to SQL queries made by Laravel
We've released a new package called spatie/laravel-sql-commenter. This one can add comments to SQL queries. These comments allow you to easily pinpoint the origin of a query when looking at your query log.
Encrypting Laravel Eloquent models with CipherSweet
– rias.be
We've just released laravel-ciphersweet. This package is a wrapper over CipherSweet, which allows you to easily use it with Laravel's Eloquent models.
Read more [rias.be]
Introducing sidecar-browsershot
– stefanzweifel.io - submitted by Stefan Zweifel
A short introduction to sidecar-browsershot package: How it works and for what it can be used for.
Read more [stefanzweifel.io]
Using Laravel Vite to automatically refresh your browser when changing a Blade file original
Yesterday, the Laravel team released the vite-plugin. Going forward, Vite will become the standard build tool for Laravel apps.
One of the cool features of this Vite integration is that you'll get hot reloading by default. Whenever you run Vite with npm dev and modify a JS or CSS file, Vite will automatically recompile the assets and refresh your browser. This way, you won't have to refresh your browser manually after making a change.
Wouldn't it be cool if this automatic refresh would work when we're changing a Blade file?
Making Vite and Valet play nice together original
Yesterday, the Laravel team launched the official vite-plugin. From now on, Vite will be the standard build tool for Laravel. The main benefits are vastly improved build times and a more straightforward API. Want to know more about it? Head over to the official docs. There's also a migration guide to go from Mix to Vite.
When I followed that guide to upgrade the freek.dev codebase from Mix to Vite , npm dev could successfully start-up Vite, but in the browser the JS / CSS did not load. Let's review how I could fix that.
Using the `Attachable` interface to attach any kind of object to a mail in a Laravel app original
Laravel 9 has gained a excellent new way to attach files in mails. Using the Attachable interface, you can specify what should happen when an object gets used as an attachment.
Using our media library package you can easily associate any file with an Eloquent model. We've added support for Laravel's Attachable in the latest version of the package.
In this blog post, I'd like to tell you all about it.
Highlighting code using Sidecar & Shiki
– rias.be
Shiki is a beautiful syntax highlighter powered by the same language engine that many code editors use. We've just released a package that allows you to run Shiki on AWS Lambda through Sidecar.
Read more [rias.be]
A Laravel package to onboard your users
– rias.be
Onboarding your users is one of the most important things you can do in your SaaS or application. After all, first impressions matter! Caleb Porzio has created an onboard package for Laravel which we (at Spatie) recently took over development and maintenance on.
Read more [rias.be]
Add Interfaces to Laravel to Increase Code Readability and Verbosity
Personally I don't know if this is a good practice, but you (and future me) might like it.
Read more [www.aaronsaray.com]
How to use Stripe CLI with Laravel Valet to listen for events
– ralphjsmit.com - submitted by Ralph J. Smit
Use the Stripe CLI with Laravel Valet to listen to webhooks locally.
Read more [ralphjsmit.com]