How to Use The Powerful reject() Method in Laravel - Mastering Eloquent & Collection Methods

In this tutorial, we’re going to cover the reject() method in Laravel, which is a very useful tool for filtering through collections. This method is the inverse of the filter() method, as it removes any elements that do not pass a given truth test, returning a new filtered collection. Dary demonstrates how to use the reject() method with a simple variable, a callback function, and with Laravel’s Article model. He also highlights the power of the reject() method, as it allows you to pass in a custom callback function to determine the truth test for each element in the collection. 📚 New Udemy Course If you’re looking to level up your Laravel skills? My new course “Mastering Laravel 10 Query Builder, Eloquent & Relationships“ is the perfect opportunity. Learn the essential tools and techniques for building robust and scalable web applications with Laravel: 📲 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 - Twitter: - Instagram: - Blog: - Patreon: - GitHub: - TikTok: @codewithdary 📋 Table of Content 00:00 - Simple Example 02:05 - Advanced Example 03:14 - reject() vs whereNotNull() 04:12 - Outro #laravel #php #codewithdary
Back to Top