2017-05-06 76 views
0

我在我的laravel网站有这个搜索功能,它在我的localhost中工作正常。但是当我使用git hook将它部署到vultr vps时,搜索功能无法正常工作。搜索功能在localhost中正常工作,但在VPS中不能正常工作

当我点击在localhost上的搜索按钮,它会产生这样的网址:http://127.0.0.1:8000/search?query=test&location=&keywords=&_token=I5BDCrqHtdwvsSwrHTrdAAGYfdukPCgU3OAGDySw

但当部署服务器什么也没有发生,它只是做一些回传负荷。

SearchController.php

public function getSearch(Request $request) 
{ 
    $this->validate($request, [ 
     'query' => 'required_without_all:keywords,location', 
     ], ['query.required_without_all' => 'Please fill atleast one field.'] 

    ); 

    $query = $request['query']; 
    $location = $request['location']; 
    $keywords = $request['keywords']; 

    if (isset($location) && isset($query) && $keywords) { 
     $posts = Post::orderBy('created_at', 'desc')->where('title', 'like', '%' . $query . '%')->where('location', 'like', $location)->where('body', 'like', $keywords)->paginate(5); 
    } 
    ....... 
    else { 
     $query = ''; 
     $location = ''; 
     $posts = Post::orderBy('created_at', 'desc')->where('location', 'like', $location)->paginate(5); 
    } 

    return view('includes.search-index', ['posts' => $posts]);  
} 

路由/ web.php

Route::get('/search', [ 
    'uses' => '[email protected]', 
    'as' => 'search' 
]); 

search.blade.php

<form action="{{ route('search') }}" method="get" > 
    ..... 
</form> 

任何想法?看起来请求没有通过?因为我收到了一个空的请求?

回答

0

我在我的nginx/etc/nginx/sites-available/default文件中有错误。

location/{ 
      try_files $uri $uri/ /index.php?query_string; 
} 

,它应该是

location/{ 
      try_files $uri $uri/ /index.php?$query_string; 
} 
0

检查在表单动作中创建了哪个链接。如果您的.env或config中有本地主机,则可能是该路由创建了不正确的链接。否则看看你的服务器日志。

您也可以在您的控制器中进行调试。首先它会在问题出现的后续步骤中运行。

+0

'搜索?查询=测试及定位=关键字=&_标记= 4RYLKod1wTRxlblKKpRzKa6Z4YQrAzELjJNP66ti'我尝试调试并返回'query'值,但其原来一个空白页。回报必须是“测试”。 – Joseph