【发布时间】:2018-11-13 09:22:57
【问题描述】:
当我在我的应用中添加新帖子时,7 tables 会影响我添加单个帖子的时间。要获取包含所有帖子数据的所有帖子,我的简单查询如下所示:
$userPost = Post::with(['product','postattribute.attribute.category','user.userDetails'])
->offset($offset)
->limit($limit)
->whereStatus("Active")
->whereIn('product_id', $userApprovalProductIDs)
->orderBy('id','desc')
->get();
所以它会重新运行我想要的所有数据。现在我想在所有表中实现搜索查询,目前我只能搜索posts 表。
如果我正在使用 categoryTitle 搜索 category 表,我正在尝试编写类似代码
where('category.title','=', $serachTitle)
但在我的情况下它不起作用。
POST模型关系:
public function user() {
return $this->belongsTo(User::class);
}
public function product() {
return $this->belongsTo(Product::class);
}
public function postattribute() {
return $this->hasMany(PostAttribute::class);
}
POSTATTRIBUTES模型关系:
public function post() {
return $this->belongsTo(Post::class);
}
public function attribute() {
return $this->belongsTo(Attribute::class);
}
ATTRIBUTES模型关系:
public function category() {
return $this->belongsTo(Category::class);
}
public function attributes() {
return $this->belongsTo(Attribute::class);
}
我该怎么做?
【问题讨论】:
-
你能包括你的模型定义吗?
-
@MKhalidJunaid 好的,等等,,
标签: laravel laravel-5.5 laravel-query-builder