conditional clause in query 2c run query if something true

Solutions on MaxInterview for conditional clause in query 2c run query if something true by the best coders in the world

we are a community of more than 2 million smartest coders
registration for
employee referral programs
are now open
get referred to google, amazon, flipkart and more
register now
  
pinned-register now
showing results for - "conditional clause in query 2c run query if something true"
Juan Diego
01 Jun 2017
1$role = $request->input('role');
2
3$users = DB::table('users')
4                ->when($role, function ($query, $role) {
5                    return $query->where('role_id', $role);
6                })
7                ->get();
similar questions