【发布时间】:2020-04-24 03:14:43
【问题描述】:
我正在尝试为我的 PhotoAlbumn 项目创建一个动态搜索功能。所以我安装了 Nicolaslopezj Searchable。但是它还不能正常工作。
错误
Illuminate\Database\Eloquent\RelationNotFoundException 调用模型 [App\Photo] 上的未定义关系 [相册]
型号
use Illuminate\Database\Eloquent\Model;
use Nicolaslopezj\Searchable\SearchableTrait;
class Photo extends Model{
use SearchableTrait;
protected $searchable = [
/**
* Columns and their priority in search results.
* Columns with higher values are more important.
* Columns with equal values have equal importance.
*
* @var array
*/
'columns' => [
'albums.name' => 10,
'photos.title' => 10,
'photos.info' => 10,
'albums.title' => 5,
],
'joins' => [
'albums' => ['photos.id','albums.id'],
],
];
protected $fillable = array('photo','title','info','album_id');
public function album(){
return $this->belongsTo('App\Album');
}
照片控制器
public function search(Request $request){
$query = $request->input('query');
$result = Photo::search($query)
->with('albums')
->get();
return view('search.results')->with('result', $result);
}
这种关系在使用 Nicolaslopezj Searchable 之前有效。
【问题讨论】:
标签: laravel searchable