Laravel: dynamic where clause with Elouquent

前端 未结 6 1228
温柔的废话
温柔的废话 2021-02-05 03:44

I am calling URL with search params which are dynamic. How could I form proper Eloquent query?

In theory:

  1. query
  2. query whe
6条回答
  •  谎友^
    谎友^ (楼主)
    2021-02-05 04:19

    You can use like this
    
    $validateUserDetail = User::query();
    if (!empty($userDetails['email'])) {
        $validateUserDetail->whereemail($userDetails['email']);
    }if (!empty($userDetails['cellphone'])) {
        $validateUserDetail->wherecellphone($userDetails['cellphone']);
    }
    $validateUserDetail->select('username');
    $validateUserDetail->get()
    

提交回复
热议问题