Twitter bootstrap &引用;未定义变量";搜索功能
我试图为从数据库获取和保存数据的表设置搜索功能。目前,我的表可以查看数据库中的数据,但无法搜索。 下面是我显示数据的表格Twitter bootstrap &引用;未定义变量";搜索功能,twitter-bootstrap,laravel-5.8,Twitter Bootstrap,Laravel 5.8,我试图为从数据库获取和保存数据的表设置搜索功能。目前,我的表可以查看数据库中的数据,但无法搜索。 下面是我显示数据的表格 <table class="table"> <thead class=" text-primary"> <th> Brand Name </th
<table class="table">
<thead class=" text-primary">
<th>
Brand Name
</th>
<th>
Phone
</th>
<th>
Reg No.
</th>
<th>
Certificate
</th>
<th>
Email
</th>
<th>
User-Role
</th>
<th>
Edit
</th>
<th>
Delete
</th>
</thead>
<tbody>
@foreach($user as $receiver)
<tr>
<td>
{{$receiver->name}}
</td>
<td>
{{$receiver->phone}}
</td>
<td>
{{$receiver->regno}}
</td>
<td>
{{$receiver->certificate}}
</td>
<td>
{{$receiver->email}}
</td>
<td>
{{$receiver->usertype}}
</td>
<td>
<a href="/org-edit/{{$receiver->id}}" class="btn btn-success">EDIT</a>
</td>
<td>
<form class = "delete" action="org-delete/{{$receiver->id}}" method="post">
{{csrf_field()}}
{{method_field('DELETE')}}
<button class="delete btn btn-danger" type="submit">Delete</button>
</form>
</td>
</tr>
@endforeach
<script>
$(".delete").on("submit", function(){
return confirm("Are you sure?");
});
</script>
</tbody>
</table>
路线呢
Route::any('/searchorg','Admin\OrganizationController@search');
每当我在搜索表单上搜索某个内容时,它都会出现错误“undefined variable:q1”
我将感谢任何帮助。谢谢您应该更改控制器:
public function search(Request $request)
{
$q1 = Input::get( 'q1' );
if( !empty( $q1 ) ) {
$user1 = User::where('name','LIKE','%'.$q1.'%')->orWhere('email','LIKE','%'.$q1.'%')->orWhere('phone','LIKE','%'.$q1.'%')->orWhere('usertype','LIKE','%'.$q1.'%')->orWhere('regno','LIKE','%'.$q1.'%')->orWhere('lat','LIKE','%'.$q1.'%')->orWhere('long','LIKE','%'.$q1.'%')->get();
if(count($user1) > 0){
return view('admin.register')->withDetails('user',$user1);
} else {
return view ('admin.register')->withMessage('No Details found. Try to search again !');
}
} else {
$user = User::where('usertype', 'organization')->get();
return view('admin/organization.organizations')->with('user',$user);
}
}
您应该在控制器中进行更改:
public function search(Request $request)
{
$q1 = Input::get( 'q1' );
if( !empty( $q1 ) ) {
$user1 = User::where('name','LIKE','%'.$q1.'%')->orWhere('email','LIKE','%'.$q1.'%')->orWhere('phone','LIKE','%'.$q1.'%')->orWhere('usertype','LIKE','%'.$q1.'%')->orWhere('regno','LIKE','%'.$q1.'%')->orWhere('lat','LIKE','%'.$q1.'%')->orWhere('long','LIKE','%'.$q1.'%')->get();
if(count($user1) > 0){
return view('admin.register')->withDetails('user',$user1);
} else {
return view ('admin.register')->withMessage('No Details found. Try to search again !');
}
} else {
$user = User::where('usertype', 'organization')->get();
return view('admin/organization.organizations')->with('user',$user);
}
}
q1
取消定义,因为您在$q
中分配了q1
取消定义,因为您在$q
中分配了。
public function search(Request $request)
{
$q1 = Input::get( 'q1' );
if( !empty( $q1 ) ) {
$user1 = User::where('name','LIKE','%'.$q1.'%')->orWhere('email','LIKE','%'.$q1.'%')->orWhere('phone','LIKE','%'.$q1.'%')->orWhere('usertype','LIKE','%'.$q1.'%')->orWhere('regno','LIKE','%'.$q1.'%')->orWhere('lat','LIKE','%'.$q1.'%')->orWhere('long','LIKE','%'.$q1.'%')->get();
if(count($user1) > 0){
return view('admin.register')->withDetails('user',$user1);
} else {
return view ('admin.register')->withMessage('No Details found. Try to search again !');
}
} else {
$user = User::where('usertype', 'organization')->get();
return view('admin/organization.organizations')->with('user',$user);
}
}