请求的控制器是这样的:
public function update(Request $request, $id)
{
$goods = Goods::findOrFail($id);
$amount = $request->get('amount');
switch ($amount) {
case 10:
$price = Price::findOrFail(1);
break;
case 20:
$price = Price::findOrFail(2);
break;
case 30:
$price = Price::findOrFail(3);
break;
default:
$price = Price::findOrFail(4);
break;
}
$goods->price = $price->price; //这一句会触发查询Algolia
return $price;
}
return $price;
会这样报错:
AlgoliaException in Client.php line 748:
Hosts unreachable: Connection timed out after 2000 milliseconds,Could not resolve host: L73SHQWTEB-1.algolianet.com,Could not resolve host: L73SHQWTEB-3.algolianet.com,Could not resolve host: L73SHQWTEB-2.algolianet.com
原因:
Goods模型中使用了algolia,$goods->price = $price->price;
会触发到对goods表的查询,所以查询会到algolia的索引数据库中去查询。
class Goods extends Model
{
use Searchable;//使用algoliasearch-laravel要加上这一句,把这一句注释掉测试,即可正常工作,可是这里需要保留
}
可是这里需要查询本地数据库,要怎么改一下?