【发布时间】:2021-04-02 11:30:43
【问题描述】:
我试图在表中搜索学生的姓名或 ID,但我不知道如何使用路由器和控制器来执行此操作。我已经有了带有按钮的表格和搜索表单我需要列表来显示所有数据,然后在搜索名称时只显示输入的数据
这是我的搜索表单
<!-- Search form -->
<form class="d-flex align-items-center flex-nowrap" action="/search">
<input name="q" class="form-control" type="text" placeholder="Search" aria-label="Search">
<button class="btn btn-sm btn-info">Search</button>
</form>
这是桌子
<table class="table">
<thead class="thead-light">
<tr>
<th scope="col">id</th>
<th scope="col">First name</th>
</tr>
</thead>
<tbody>
@foreach($students as $student)
<tr>
<td>{{ $student->cne }}</td>
<td>{{ $student->firstName }}</td>
<td>
<a href="{{ url('/edit/'.$student->id )}}" class="btn btn-sm btn-warning">Edit</a>
</td>
</tr>
@endforeach
</tbody>
</table>
我会喜欢实时搜索的东西,这样我就可以摆脱搜索按钮了,哈哈 谢谢
【问题讨论】:
-
嗨 Fathi,请给我们看一下这个控制器。实时搜索也需要一些javascript。结帐 Livewire 可能会这样做。
-
嗨@RachidS,我没有为搜索制作控制器。我会搜索 Livewire
-
我建议使用 Livewire,尤其是当您需要这种功能时。这是您想要做的确切事情的文档页面:laravel-livewire.com/docs/2.x/query-string 如果您想走得更远,Laracasts 上有很棒的课程或 youtube 上的一些免费课程:youtu.be/HWTF-oi70e4