whereAny() Query Builder Example In Laravel

  Mar 2024
  ITSolutionsGuides
  Category: Laravel
whereAny() Query Builder Example In Laravel

Welcome To ITSolutionsGuides,


The Laravel team released v10.47 which added the added feature of whereAny(), which was a new methods can search against multiple columns or logic. While we need to search multiple columns we will create the multiple or for building the search query. Query Builder whereAny() has reduced the query much simpler. In Laravel, the whereAny() method in Query Builder allows filtering records based on any of the given conditions, providing flexibility and efficiency in querying databases. Lets see how to use Query Builder whereAny()

Let's Start Coding

// Before using `orWhere`
User::query()
    ->where(function ($query) use ($search) {
    $query
        ->where('first_name', 'LIKE', $search)
        ->orWhere('last_name', 'LIKE', $search)
        ->orWhere('email', 'LIKE', $search)
        ->orWhere('phone', 'LIKE', $search);
    });
 
// Using `whereAny`
User::whereAny(
    [
        'first_name',
        'last_name',
        'email',
        'phone'
    ],
    'LIKE',
    "%$search%"
);

We hope it helps everyone. Thanks for supporting ITSolutionsGuides and keep supporting us also follow us in social media platforms.

Subscribe for NewsLetter

Be the first to know about releases and tutorial news and solutions.

We care about your data in our privacy policy.

ITSolutionsGuides

ITSolutionsGuides was started mainly to provide good and quality web solutions for all the developers. We provide tutorials to support all the developers and also we try to provide solutions to the errors we face while coding.

Contact US

ITSolutionsGuides, provide users with an easy-to-use form to reach out for support or inquiries.

whatsapp  gmail  instagram-new--v1  facebook-circled  twitter-circled  linkedin  github  pinterest 

Copyright © 2023 - 2024 All rights reserved | ITSolutionsGuides