【发布时间】:2018-02-10 12:16:57
【问题描述】:
所以我有这个搜索表单,如果用户输入数据库中不存在的内容,我想显示一条消息,例如“未找到”这样的消息,因为我现在拥有的只是显示一个空表,如果它没有什么都找不到。我怎么做这个?这是我的搜索表单的代码
buildings.blade.php
{!! Form::open(['method'=> 'GET','url'=>'offices','role'=>'search']) !!}
<div class="input-group col-xs-4 col-md-6" >
<input type="text" name="search" class="form-control" placeholder="Search..." required>
<span class="input-group-btn">
<button type="submit" class="btn btn-info btn-md">
<span class="glyphicon glyphicon-search"></span> Search
</button>
</span>
</div>
{!! Form::close()!!}
OfficeController.php
public function index(Request $request) {
$search = \Request::get('search');
$offices = Office::where('name', 'LIKE', '%' . $search . '%')->get();
return view('search', compact('offices', 'search'));
}
【问题讨论】:
-
你运行的是什么版本的php?
-
我的是 php 7.2.1 @btl