简体   繁体   English

搜索功能可以在localhost上正常运行,但不能在VPS中运行

[英]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.

相关问题 PHP Bootstrap可以在localhost上完美运行,但不能在VPS上运行 - PHP Bootstrap working perfectly on localhost but not working on VPS 为什么 CodeIgniter 中的重定向功能在实时服务器上不起作用,但在 localhost 上运行良好 - Why in CodeIgniter redirect function is not working on live server, but working fine on localhost 本地主机工作正常,但phpmyadmin不是 - localhost working fine but phpmyadmin is not 会话在本地主机上工作正常但在服务器上不工作 - Session in working fine in localhost but not at server Captcha 在 localhost 上工作正常,但不能在线 - Captcha is working fine on localhost , but not online Phpmailer 在 localhost 中工作正常但不在服务器中 - Phpmailer working fine in localhost But not in server fullcalendar在localhost中工作正常,但在服务器中工作不正常 - fullcalendar is working fine in localhost but not in server 为什么DomPdf在共享托管上可以正常工作,但在VPS托管上却不能正常工作? - why DomPdf is working fine on shared hosting but not on VPS hosting? 我的 spl_autoload_register() function 不适用于 cpanel 但在 localhost 中工作正常 - My spl_autoload_register() function is not working for cpanel but working fine in localhost $ .post和AJAX不能在服务器上运行,但在localhost中工作正常 - $.post & AJAX is not working on server, but working fine in localhost
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM