У меня есть этот класс модели:
class Billings extends Model
{
protected $table = 'billings';
protected $fillable = [
'msisdn',
'created_at',
'amount',
'billing_channel',
];
protected $guarded = [
'id'
];
}
Контроллер
public function billingsReport(Request $request)
{
$billings = DB::table('billings')
->select(
'msisdn',
DB::raw('created_at as created_date'),
'amount',
'billing_channel'
)
->orderByRaw('created_at DESC');
$render=[];
if(isset($request->msisdn))
{
$billings=$billings->where('msisdn','like','%'.$request->msisdn.'%');
$render['msisdn']=$request->msisdn;
}
if(isset($request->billing_channel))
{
$billings=$billings->where('billing_channel','like','%'.$request->billing_channel.'%');
$render['billing_channel']=$request->billing_channel;
}
$billings= $billings->orderBy('created_at','DESC');
$billings= $billings->paginate(15);
$billings= $billings->appends($render);
$data['billings'] = $billings;
return view('report.billingsReport',$data);
}
Обратите внимание, что поле billing_channel находится в таблице счетов
Вид
<div class="row" style="margin-bottom: 10px">
{{ Form::model(request(),['method'=>'get']) }}
<div class="col-sm-2">
{{ Form::text('msisdn',null,['class'=>'form-control','placeholder'=>'MSISDN']) }}
</div>
<div class="col-xs-2">
{{ Form::submit('Search',['class'=>'btn btn-warning']) }}
</div>
{{ Form::close() }}
</div>
Уже работает текстовый фильтр для msisdn.
Из моего контроллера и представления я фильтрую msisdn, а также использую form :: text в представлении.Вопрос в том, как мне также отфильтровать billing_channel, используя form :: select
Как мне изменить мою модель, представление и контроллер для этого?