Laravel 8查询正在开发中,但在部署到Heroku时没有



我在Laravel中有一个自动完成搜索控制器,它对搜索控制器进行ajax调用:

public function autocomplete(Request $request)
{ 
$data = Subject::where('title', 'LIKE', $request->subject.'%')->take(8)->get();
$output = '<ul class="origin-top-right right-0 mt-2 w-56 shadow-lg bg-white ring-1 ring-black ring-opacity-5" style="display:block; position:relative; overflow-y: scroll;">';
if (count($data)>0) {
foreach ($data as $row){
$output .= '<li><button style="text-align: left;" class="w-full block px-4 py-2 text-sm text-gray-700 hover:bg-gray-100 hover:text-gray-900" role="menuitem">'.$row->title.'</button></li>';
}
}
else {
$output .= '<li><button style="text-align: left;" class="w-full block px-4 py-2 text-sm text-gray-700 hover:bg-gray-100 hover:text-gray-900" role="menuitem">'.'No results'.'</button></li>';
}

$output .= '</ul>';
return $output;
}

dev数据库是mysql,prod是pgsql,跟踪代码显示$data = Subject::where('title', 'LIKE', $request->subject.'%')->take(8)->get();行在生产中返回空,但在开发中填充正确,我已经检查了我的prod数据库是否正确播种,Subject模型是否正常工作,请帮助,谢谢!

我已经更新了您的控制器文件来替换它。

问题是,在localhost中,小写或小写都可以正常工作,而在实时服务器中,大写和小写都是不同的值,所以这就是问题所在,现在我已经解决了您的解决方案。

CountryController

namespace AppHttpControllers;
use IlluminateHttpRequest;
use AppCountry;
use DB;
class CountryController extends Controller
{
public function autocomplete(Request $request)
{ 
// return Country::all();
if($request->ajax()) {
//$data = Country::where('name', 'LIKE', $request->country.'%')->take(10)->get();
$data = Country::where(DB::raw('LOWER(name)'), 'like',  strtolower($request->country) . '%')->limit(10)->get();
//dd($data->toArray());
$output = '<ul class="origin-top-right right-0 mt-2 w-56 rounded-md shadow-lg bg-white ring-1 ring-black ring-opacity-5" style="display:block; position:relative; overflow-y: scroll;">';
if (count($data)>0) {
foreach ($data as $row){
$output .= '<li><button style="text-align: left;" class="w-full block px-4 py-2 text-sm text-gray-700 hover:bg-gray-100 hover:text-gray-900" role="menuitem">'.$row->name.'</button></li>';
}
}
else {
$output .= '<li><button style="text-align: left;" class="w-full block px-4 py-2 text-sm text-gray-700 hover:bg-gray-100 hover:text-gray-900" role="menuitem">'.'No results'.'</button></li>';
}
$output .= '</ul>';
return $output;
}
}
public function update_countries(Request $request){
$countries = Country::all();
dd($request);
}
}