我有一个文本框,我试图用来搜索数据库,我想要实现的是当我输入出生日期(例如14/06/1996)时textbox(searchdob)它将在数据库中显示具有此出生日期值的用户。我已经尝试过使用我的AppointmentController来执行where条件,以便foreach循环保持整洁。
错误是:非静态方法Symfony \ Component \ HttpFoundation \ Request :: get()不应该静态调用,假设$ this来自不兼容的上下文
AppointmentController
function addAppointment()
{
$doctors = Doctor::all();
$search = Request::get('searchdob');
$users = User::where('role', '=', 1)
->where('dateofbirth', 'LIKE', '%'.$search.'%')
->get();
return view('appointment/addappointmentform',['users'=>$users],['doctors'=>$doctors]);
}
addappointment.blade
<form>
Insert Patients date of birth
<input
type="text"
name="searchdob"
id="searchdob"
placeholder="dd/mm/yyyy"
onkeyup="
var v = this.value;
if (v.match(/^\d{2}$/) !== null) {
this.value = v + '/';
} else if (v.match(/^\d{2}\/\d{2}$/) !== null) {
this.value = v + '/';
}"
maxlength="10"
></form>
<fieldset>
<legend>Select the Patient</legend>
@foreach($users as $user)
<div>
<label for="dirBtn{{$user->id}}">
<input id="dirBtn{{$user->id}}" type="radio" name="user" value="{{$user->id}}">
{{$user->firstname}}
</label>
</div>
@endforeach
</fieldset>
答案 0 :(得分:2)
将其更改为:
$search = request('searchdob');