【发布时间】:2021-07-18 07:33:21
【问题描述】:
我有一个单词表,我想在我的索引视图中保留一个搜索表单来搜索想要的单词。
这是我在控制器中编写的用于搜索的函数。
public function search(string $id){
if($id!="")
{
$terms = Terms::query()
->where('term', $id)
->get();
if(count($terms)==0)
{
$terms = Terms::query()
->where('term', 'LIKE', "{$id}%")
->orWhere('term', 'LIKE', "%{$id}%")
->get();
}
if(count($terms)==0)
{
$terms = Terms::query()
->orWhere('term', 'LIKE', "%{$id}%")
->get();
}
return view('admin/terms/search')->with('terms', $terms);
}
}
这是我的表单代码
{!! Form::open(['action' => 'App\Http\Controllers\TermsController@search', 'method' => 'GET']) !!}
<form class="bd-forms">
<div class="form-group">
{{ Form::label('word', 'Search word') }}
{{ Form::text('word', '', ['class' => 'form-control', 'placeholder' => 'type word here']) }}
@error('word')
<div class=""
style="padding-right:5px;margin-top:5px;margin-bottom:10px; color:red;font-size:12px;">
the field is empty.
</div>
@enderror
</div>
<div>
{{ Form::submit('Search', ['class' => 'btn btn-primary']) }}
</div>
</form>
{!! Form::close() !!}
现在我想知道如何将文本值作为$id 参数发送到搜索函数,方法应该是“GET”还是“POST”?
【问题讨论】: