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

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