[英]Search function working fine in localhost but not in VPS
I have this search function in my laravel website, its working fine in my localhost. 我在laravel网站中具有此搜索功能,在我的本地主机中可以正常工作。 But when I deployed it in vultr vps using git hook, the search function is not working properly.
但是,当我使用git hook在vultr vps中部署它时,搜索功能无法正常工作。
When i click the search button in localhost, it will produce a url of like this: http://127.0.0.1:8000/search?query=test&location=&keywords=&_token=I5BDCrqHtdwvsSwrHTrdAAGYfdukPCgU3OAGDySw
当我单击本地主机中的搜索按钮时,它将产生一个类似以下的URL:
http://127.0.0.1:8000/search?query=test&location=&keywords=&_token=I5BDCrqHtdwvsSwrHTrdAAGYfdukPCgU3OAGDySw
: http://127.0.0.1:8000/search?query=test&location=&keywords=&_token=I5BDCrqHtdwvsSwrHTrdAAGYfdukPCgU3OAGDySw
: http://127.0.0.1:8000/search?query=test&location=&keywords=&_token=I5BDCrqHtdwvsSwrHTrdAAGYfdukPCgU3OAGDySw
search? http://127.0.0.1:8000/search?query=test&location=&keywords=&_token=I5BDCrqHtdwvsSwrHTrdAAGYfdukPCgU3OAGDySw
_ http://127.0.0.1:8000/search?query=test&location=&keywords=&_token=I5BDCrqHtdwvsSwrHTrdAAGYfdukPCgU3OAGDySw
but when in the deploy server nothing happens, it just do some postback load. 但是在部署服务器中什么也没有发生时,它只会做一些回发负载。
SearchController.php 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]);
}
routes/web.php 路线/ web.php
Route::get('/search', [
'uses' => 'SearchController@getSearch',
'as' => 'search'
]);
search.blade.php search.blade.php
<form action="{{ route('search') }}" method="get" >
.....
</form>
Any idea? 任何想法? It seems that the request is not passing?
似乎请求没有通过? Because I got an empty request?
因为我有一个空的请求?
Check what link is created in form action. 检查在表单操作中创建了什么链接。 If you have localhost in your .env or config possible that route create incorrect link.
如果您的.env或配置中有本地主机,则该路由可能会创建错误的链接。 Otherwise look at your server logs.
否则,请查看您的服务器日志。
You can debug also in your controller. 您也可以在控制器中调试。 As first does it run, in next steps where the problem is.
它首先运行,然后在下一步中解决问题。
I have an error in my nginx
/etc/nginx/sites-available/default
file. 我的
nginx
/etc/nginx/sites-available/default
文件中存在错误。
location / {
try_files $uri $uri/ /index.php?query_string;
}
and it should be 它应该是
location / {
try_files $uri $uri/ /index.php?$query_string;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.