laravel 多条件查询

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/cofecode/article/details/84305118

sql拼接

blade.php

<form action="" method="post">
{{csrf_field()}}
提现查询
<select name="type" >
  <option value ="微信">微信</option>
  <option  value ="支付宝">支付宝</option>
</select>
<p>提现人:<input type="text" name="name"><br></p>

单号:<input type="text" name="sn"><br>
<p>
<input type="submit" value="提交">
</p>

ui 大致长这个样子
可以输入提现方式以及提现人、提现单号进行多条件查询。

$data = DB::table('funds_log')->select('funds_log.amount', 'funds_log.source','funds_log.channel','user_info.nickname') -> leftJoin('user_info','funds_log.user_id','=','user_info.user_id');

if ($_REQUEST['type']) {
    $data =  $data->where('channel','like', $_REQUEST['type']);
}

if ($_REQUEST['sn']) {
    $data =  $data->where('source', 'like', '%' . $_REQUEST['sn'] . '%');
}

if ($_REQUEST['name']) {
    $data =  $data->where('nickname', 'like', '%' . $_REQUEST['name'] . '%');
}
$res = $data->get();

猜你喜欢

转载自blog.csdn.net/cofecode/article/details/84305118