我嘗試laravel本教程的Live搜索Laravel路線的搜索
但它在homepage(index)
我想它訪問localhost/laravel/public/search
這裏是控制器
class SearchController extends Controller
{
public function index()
{
return view('search.search');
}
public function search(Request $request)
{
if ($request->ajax())
$output ="";
$orderinfo=DB::table('tb_order')->where('shipcustomername','LIKE','%' . $request->search.'%')
->orWhere('orderId','LIKE','%' .$request->search. '%')->get();
if ($orderinfo)
{
foreach ($orderinfo as $key =>$orderinfo){
$output.='<tr>' .
'<td>' .$orderinfo->orderId .'</td>' .
'<td>' .$orderinfo->email .'</td>' .
'<td>' .$orderinfo->subsource .'</td>' .
'</tr>';
}
return Response($output);
}
和我的路線
Route::get('/' ,'[email protected]');
Route::get('/search' ,'[email protected]');
在我的資源文件夾 我有文件夾,搜索,它是包含search.blade.php
<div class="container">
<div class="row">
<div class="panel panel-default">
<div class="panel-heading">
<h3>Order Info</h3>
</div>
<div class="panel-body">
<div class="form-group">
<input type="text" class="form-control" id="search" name="search"></input>
</div>
<table class="table table-bordered table-hover ">
<thead>
<tr>
<th>OrderID</th>
<th>Email</th>
<th>SubSource</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
</div>
</div>
<script type="text/javascript">
$('#search').on('keyup',function(){
$value=$(this).val();
$.ajax({
type : 'get',
url : '{{URL::to('search')}}',
data : {'search':$value},
success:function(data){
$('tbody').html(data);
}
});
});
</script>
</body>
我知道這是對指數的路線,
Route::get('/' ,'[email protected]');
但如果試圖改變這種到
Route::get('search' ,'[email protected]');
我得到錯誤500
什麼是正確的方式來路由這個,所以它不會使用索引
謝謝
嘗試更改'路線:: get('search','SearchController @ index');'到'Route :: get('/ search', 'SearchController @ index');' –
請添加搜索刀片 –
@Leo_Kelmendi我也有search.blade.php查看文件夾 –