Laravel Collection Filtering: Tips and Tricks #shorts

preview_player
Показать описание
This YouTube short will show you how you could use Laravel its filter method on your collections to write your own logic. The filter method filters a collection using the given callback, keeping only those items that pass a given truth test.

📲  Let’s plan a meeting
Plan a (paid) 1-hour meeting on Calendly to do portfolio reviews, code reviews resume reviews or a coaching session for Laravel

💌 Newsletter
Sign up for my free weekly email newsletter

🔥 Resources

#youtube #shorts
Рекомендации по теме
Комментарии
Автор

You should avoid getting all records from the database. It would be better to use where and filter data this way.

dailyshowup
Автор

The filter method of the Collection is useful for filtering the data of a collection. However, in this example, it would be more efficient to filter the users directly in the query :)

alessandro_amos
Автор

Users::where('is_admin', true)->count();

eziosan
Автор

It looks very similar to doctrine collection.., but it filter the results tho...
i dont know how it works in laravel

nogerivan
Автор

is not better use a getter on the model and return if the user is admin?

tripulante
Автор

this is a bad example of using filter in collection, you don't need to grab all users and filter them.

tihouatimohamedlamine
Автор

what if you have millions and millions users? its better to filter with the query like from an array.

kisstamas