πŸ”₯ Weekly thread #04 of 2022

πŸ”₯ This week's code tips for Laravel developers

A weekly thread 🧡

Use Eloquent scopes to clean up complex relation queries

4

πŸ”₯ Use Eloquent scopes to clean up complex relation queries

Use Eloquent scopes to clean up complex relation queries

πŸ”₯ Eloquent scopes pair very well with complex relation queries

Scopes should also have @method annotations. They make the model more self-documenting & better supported in IDEs

Use PostgreSQL's trigram indexes to make WHERE LIKE queries faster

3

πŸ”₯ Use PostgreSQL's trigram indexes to make WHERE LIKE queries faster

Use PostgreSQL's trigram indexes to make WHERE LIKE queries faster

⚑️ Database Tip

Every database performance guide is repeating the false statement stating WHERE LIKE '%search%' queries can't use an index. That is just not true! Most probably your database can't, but PostgreSQL implements trigram indexes which will make this really fast!

Laravel's container can be used for resolving variadic dependencies

2

πŸ”₯ Laravel's container can be used for resolving variadic dependencies

Laravel's container can be used for resolving variadic dependencies

Since @laravelphp 8.79 it is possible to resolve variadic dependencies out of the IoC container.

This is quite useful for type-hinting and static analysis and allows us to bind a set of concrete implementations to an abstraction layer.

#Laravel #PHP

We're writing a book, you can get it for free here.