2017-05-06 77 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