[英]search in laravel database with live results
I'm working with Laravel 5.4 and I have a list of users in admin panel I want to add search box in top of my users list to search them and I want to results be live (when typing words results shows) I guess should use Ajax for that(not sure!) 我正在使用Laravel 5.4,并且在管理面板中有一个用户列表,我想在我的用户列表顶部添加搜索框以搜索他们,并且我希望结果保持实时(当输入单词结果显示时)我猜应该使用为此使用Ajax(不确定!)
Let say this is my users list code: 可以说这是我的用户列表代码:
@foreach ($users as $user)
<td>{{ $user->first_name }}</td>
<td>{{ $user->last_name }}</td>
<td>{{ $user->username }}</td>
<td>{{ $user->email }}</td>
@endforeach
How can I get that search to work with it? 我如何获得与之配合的搜索?
Should I install any plugin or just use Vue.Js or ...? 我应该安装任何插件还是仅使用Vue.Js或...?
Thanks. 谢谢。
您实际上必须为此使用ajax技术..但只能使用一次..让angularJS或vue执行搜索功能..我实际上想在此处发布摘要,但似乎有一个错误..所以这里是您可能想要的示例见..
You could use https://datatables.net/ 您可以使用https://datatables.net/
Include in your html (if you're using gulp, use in your file who controls the dependencies) 包含在html中(如果您使用的是gulp,请在文件中使用由谁来控制依赖项)
<table id="myTable"> <thead> <th>First name</th> <th>Last name</th> <th>Username</th> <th>Email</th> </thead> <tbody> @foreach($users as $user) <td> {{ $user->first_name }} </td> <td> {{ $user->last_name }} </td> <td> {{ $user->username}} </td> <td> {{ $user->email }} </td> @endforeach </tbody> </table> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/datatables/1.10.15/css/dataTables.bootstrap.css" /> <script src="https://cdnjs.cloudflare.com/ajax/libs/datatables/1.10.15/js/jquery.dataTables.js"> <script> $(document).ready(function(){ $('#myTable').DataTable(); }); </script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.