Reputation: 45
I am trying to create a dynamic serch function to my PhotoAlbumn project. So I have installed Nicolaslopezj Searchable. However it does not work propertly as yet.
Error
Illuminate\Database\Eloquent\RelationNotFoundException Call to undefined relationship [albums] on model [App\Photo]
Model
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');
}
PhotoController
public function search(Request $request){
$query = $request->input('query');
$result = Photo::search($query)
->with('albums')
->get();
return view('search.results')->with('result', $result);
}
This relationship worked prior to using Nicolaslopezj Searchable.
Upvotes: 0
Views: 118
Reputation: 2951
You have an extra s
in your relationship.
Replace
$result = Photo::search($query)
->with('albums')
->get();
by
$result = Photo::search($query)
->with('album')
->get();
Upvotes: 0