我正在尝试将一些现有记录导入到 algolia。现在使用Laravel 5.5
并scout 3.0.0
与 algolia-php-sdk 一起使用。当我执行时php artisan scout:import "App\Listings" -v
,它会引发以下异常
[BadMethodCallException]
Call to undefined method Illuminate\Database\Query\Builder::searchable()
Exception trace:
() at /home/vagrant/Code/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php:2457
Illuminate\Database\Query\Builder->__call() at /home/vagrant/Code/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php:1273
Illuminate\Database\Eloquent\Builder->__call() at /home/vagrant/Code/vendor/laravel/scout/src/Searchable.php:102
App\Listings::makeAllSearchable() at /home/vagrant/Code/vendor/laravel/scout/src/Console/ImportCommand.php:43
Laravel\Scout\Console\ImportCommand->handle() at n/a:n/a
call_user_func_array() at /home/vagrant/Code/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php:29
Illuminate\Container\BoundMethod::Illuminate\Container\{closure}() at /home/vagrant/Code/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php:87
Illuminate\Container\BoundMethod::callBoundMethod() at /home/vagrant/Code/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php:31
Illuminate\Container\BoundMethod::call() at /home/vagrant/Code/vendor/laravel/framework/src/Illuminate/Container/Container.php:549
Illuminate\Container\Container->call() at /home/vagrant/Code/vendor/laravel/framework/src/Illuminate/Console/Command.php:180
Illuminate\Console\Command->execute() at /home/vagrant/Code/vendor/symfony/console/Command/Command.php:262
Symfony\Component\Console\Command\Command->run() at /home/vagrant/Code/vendor/laravel/framework/src/Illuminate/Console/Command.php:167
Illuminate\Console\Command->run() at /home/vagrant/Code/vendor/symfony/console/Application.php:888
Symfony\Component\Console\Application->doRunCommand() at /home/vagrant/Code/vendor/symfony/console/Application.php:224
Symfony\Component\Console\Application->doRun() at /home/vagrant/Code/vendor/symfony/console/Application.php:125
Symfony\Component\Console\Application->run() at /home/vagrant/Code/vendor/laravel/framework/src/Illuminate/Console/Application.php:88
Illuminate\Console\Application->run() at /home/vagrant/Code/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php:121
Illuminate\Foundation\Console\Kernel->handle() at /home/vagrant/Code/artisan:35
`
我Searchable
在模型中包含了 trait 以及toSearchableArray()
自定义插入记录的方法。
我有另一个模型叫做Store
. 我可以毫无问题地将该模型导入 algolia。我已经通过这个链接。但是我的两个模型都扩展了相同的 basemodel 类,所以上面的链接也没有帮助我。
任何有关前进的提示将不胜感激。
编辑 代码示例
namespace App;
use App\Services\Search\Builders\ListingRecordBuilder;
use Laravel\Scout\Searchable;
.
.
.
class Listings extends BaseModel
{
use Searchable;
.
.
.
public function searchableAs()
{
return 'local_listings_new';
}
public function toSearchableArray()
{
$recordBuilder = new ListingRecordBuilder($this);
return $recordBuilder->buildRecord();
}
}