Introducing Scout Extended
Last month at the Laravel PHP Paris meetup, Nuno Maduro introduced his newest package called Scout Extended.
Last month at the Laravel PHP Paris meetup, Nuno Maduro introduced his newest package called Scout Extended.
Jonathan Reininck wrote a cool article on how you can create dynamic releationships. This technique will keep the number of queries and the memory used to a minimum.
I hope that gives you a good overview of how you can use subqueries to create dynamic relationships in Laravel. This is a powerful technique that allows you to push more work into the database layer of your app. This can have a huge impact on performance by allowing you to drastically reduce the number of database queries executed and overall memory used.
Read more [reinink.ca]
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.
"As a Laravel developer, this is the one newsletter I most look forward to. Freek has a talent for distilling packages or techniques down to something immediately useful - one tip can save you hours and even weeks. It's concise and practical and highly relevant."
Did you know that you can define a $dispatchesEvents property on your Eloquent model and map native Eloquent events to your own event classes? ? Check this out: pic.twitter.com/P205GTIYEc
— Laravel Docs Daily (@laradocsdaily) November 24, 2018
Read more [twitter.com]
I've been using PhpStorm for quite some time now, but never took the effort to fix a few minor annoyances I had with it. Getting rid of the default comment for new PHP files First up, when creating a new PHP file or class you PhpStorm will add this comment block like this by default: /** * Created…
Q: how many api calls do you need to do in #PHP to determine if the ☀️ is up?
— Freek Van der Herten (@freekmurze) November 14, 2018
A: 0 pic.twitter.com/glaZQZ4mQ9
Read more [twitter.com]
Let's take a look at how you can define routes to controllers in Laravel. By default you can do it like this: Route::get('my-route', 'MyController@index'); This will look for the MyController class in the App\Http\Controllers namespace. This default namespace is set up in Laravel's…
The past few years I visited and spoke at a lot of PHP conferences. PHP Benelux, Laracon EU and US, PHP UK Conference, PHP World are only a few of the conferences I thoroughly enjoyed. Visiting those conferences can be recommended to anyone interested in PHP. Regardless of which level you're at…
There are three ways of loading relationships in Laravel. Tim MacDonald, a freelance dev based in Sydney, explains them all.
It is often useful to show the number of related models a given instance has, but not actually need any specific information about the related models, just how many exist. In this scenario you do not want to load all of the related models into memory to count them, we want our database to do the heavy lifting for us. Laravel offers a number of ways to retrieve relationship counts.
Read more [timacdonald.me]
Invokables in PHP are classes that you can use as a function. They have been around since PHP 5.3 and have many interesting use cases. Here's a quick example. class Invokable { public function __invoke() { echo 'I have been invoked'; } } You can use it like this: // outputs 'I have been…
The last couple of weeks soem strange Imagick errors popped up across all our servers. In a new blogpost my colleague Alex explains the cause and the fix.
Over the last few days we've had a couple of issues with Imagick and processing PDFs on our servers. As it turns out, these issues are caused by automatic security updates. Let's look into the issue and its solution.
Read more [alexvanderbist.com]
Mattias explains a problem we recently encountered at Oh Dear with Telescope.
For Oh Dear!, we're using Laravel Telescope as a convenient way of tracking/displaying exceptions, runs, ... It stores its exceptions in the database, so you can easily view them again. It stores those in a TEXT field in MySQL, which is limited to 2^16 bytes, or 65536 bytes. Some of our exceptions tend to be pretty long, and they were hitting this limit.
Read more [ma.ttias.be]
?⚾️ Just found out throw_unless returns the provided condition! This took an already super handy helper and made it ? pic.twitter.com/aaz3Oc7uye
— Caleb Porzio (@calebporzio) October 26, 2018
Read more [twitter.com]
At Spatie we do a lot of open source work. You can find a list of our packages on the open source section of our website. I'm proud to share that, according to Packagist, the Spatie packages have now been downloaded over 20 million times. The rate at which they are being downloaded is growing too.…
Rob Allen performs a cool test.
Recently I needed to test part of Slim that uses the built-in PHP functions header() and headers_sent(). To do this, I took advantage of PHP’s namespace resolution rules where it will find a function within the same namespace first before finding one with the same name in the global namespace.
Read more [akrabat.com]
Christopher Pitt has built his own new blog. Of course he uses lots of preprocessing goodness.
In fact, this whole blog is built on preprocessed code. Why? Because I want to see what I can build, using a technology that 99% of vocal PHP developers (read: people on Reddit and Twitter) scoff at. I want to show that preprocessing works well and is popular in other languages.
Read more [assertchris.io]
PHP Hero Brent Roose clearly explains the difference between array_merge and the + operator.
PHP has several ways of combining two arrays into one. There's a subtle difference between two methods though, a difference worth knowing.
Read more [stitcher.io]
? The "pluck" method in Laravel's collections can take a string with dots to get a list of deeply nested values. You can also add a star to combine deeply nested lists ?https://t.co/qckA0dLw45 pic.twitter.com/3im6dGYoTi
— Joseph Silber (@joseph_silber) October 25, 2018
Read more [twitter.com]
Whoops error pages are awesome, though sometimes you may need to analyze stack trace in PhpStorm!
— PhpStorm (@phpstorm) October 19, 2018
Tools -> Analyze Stack Trace
Can also be handy if you got a stack trace from a remote server log. pic.twitter.com/OVRb5KnBJQ
Read more [twitter.com]
While working on a package I found myself trying to combine some data. This is what my code looked like. Assume that $locales and $fields are arrays that are already populated. collect($locales)->each(function (string $locale) { collect($fields)->each(function (Field $field) use ($locale)…
Besides enjoying some greenfield work, we often have to work on legacy projects at Spatie too. Sometimes those projects don't run on the latest PHP version. I this blogpost I'd like to show you a way to switch PHP version easily when using Laravel Valet. (I know you could also use Docker or…