Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Query for multiple fields with Laravel 4.x

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 655
    Comment on it

    I have a situation where we have to make query for searching on the basis of multiple fields with Laravel 4.x. So for this we have many method either we will concatenate or we will use OR query in Laravel

    Example:

    $searchqueryResult =User::where('fname', 'LIKE', '%'.$search.'%')->orWhere('lname','LIKE', '%'.$search.'%')->orWhere('location','LIKE', '%'.$search.'%')->orWhere('summary','LIKE', '%'.$search.'%')->orWhere('headline','LIKE', '%'.$search.'%')->where('id','<>',$user&#95;id)->where('userstatus','=','approved')->orderBy('karmascore','DESC')->get();
    

    Here we can see that we have to search on the basis of (first name,last name,location,summary). By using this query we will solve this problem. We can also use concatenate to solve this problem.

    Note:Here User is a eloquent and that query is in laravel 4.x

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: