【发布时间】:2014-07-26 14:40:49
【问题描述】:
我有这两个模型
Track
id
name
artist_id
Artist
id
name
class Song extends \Eloquent{
public function artist(){
return $this->hasOne('Artist','id', 'artist_id');
}
}
class Artist extends \Eloquent{
public function songs(){
return $this->hasMany('Song', 'artist_id', 'id');
}
}
现在我想在给定搜索词“happy pharrel”的情况下实现搜索。 我很清楚,我必须搜索歌曲名称为“happy”或艺术家名称为“happy”的歌曲和歌曲名称为“pharrel”的歌曲或者艺术家的名字是“pharrel”。
现在我想知道如何对歌曲表和艺术家表进行这样的查询?
【问题讨论】:
-
您需要在表之间创建连接才能执行搜索查询。
标签: php mysql laravel laravel-4 eloquent