所以我有一个像twitter这样的应用程序,但是我想“墙”上有来自所有用户的帖子,但是要被当前用户的兴趣过滤.
我想要的东西如下:
$posts = PostModel::with('interests')->latest()->get();
$user = UserModel::find(Auth::user()->id);
foreach ($posts as $post) {
foreach($user->interests as $interest){
return only the posts
我需要计算状态为X的人,其中有多个项目。 模型:人员、项目、状态 People->items() = belongstomany with item_people table as intermediate
Items->statuses() = belongstomany with item_statuses table as intermediate People::with(['items','items.statuses' => function ($q){
$q->whereIn('
我有三种关系模式:
Tour.php
class Tour extends Model
{
public function category()
{
return $this->belongsTo('App\TourCategory', 'category_id');
}
public function region()
{
return $this->belongsTo('App\Region');
}
}
TourCategory.php
cla
我的一些关系出了问题。我有以下情况
产品:
public function catalogues()
{
return $this->belongsToMany('App\Catalogue');
}
public function category()
{
return $this->belongsTo('App\Category');
}
类别:
public function products()
{
return $this->hasMany('App\Product');
我已经使用belongsToMany函数创建了多对多关系: class Doctor extends Model
{
...
public function categories()
{
return $this->belongsToMany('App\Category', 'doctors_to_categories', 'doctor_id', 'category_id');
}
...
} 现在我想创建具有多对多条件的查询。在中的SQL中为: SELECT *
FROM `do
因此,我有如下的数据结构:
User
id
Collection
user_idgame_id
Game
idstatus
在我的模型中,我有这样的关系:
User::hasMany(Collection)
Collection::belongsTo(Game)
Game::hasMany(Collection)
所以,我要做的是获得一个用户列表,并包括所有相关的游戏通过收集表。但我只想包括那些有特殊地位的游戏。我使用的代码(不起作用)如下:
User::with('collections.game')->whereHas('collections.game
我找不到解决方案,如何检索属于活动活动的用户链接?
以下是我的模特:
用户模型:
public function links(){
return $this->hasMany('Link','user_id');
}
public function analytic(){
return $this->hasManyThrough('Analytic','Link');
}
竞选模式:
public function task(){
return $this->hasMany('Ta
以下是我的人际关系:
User hasMany licences
Licence belongsTo User
Licence hasMany attestations
Attestation belongsTo Licence
Attestation hasMany vehicles
Vehicle belongsTo Attestation
示例:
用户
id | name
1 | John Doe
许可证
id | user_id | type
1 | 1 | A
2 | 1 | B
证明
id | licence_id | date
1 | 1
这很好,但是我想知道的是,是否有更好的方法来搜索Laravel中的标签。谢谢。
标记模型:
class Tag extends Model
{
public function noticias()
{
return $this->morphedByMany('App\Models\Noticia', 'taggable');
}
// ...
}
模型:
class Noticia extends Model
{
public function tags()
{
retu
假设我有这样的DB结构:
Table A:
-id
-user_id
Table B:
-id
-user_id
Table C:
-id
-user_id
Users:
-id
这是我的用户模型
namespace App\Models;
use Illuminate\Notifications\Notifiable;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Foundation\Auth\User as Authenticatable;
class User extends Authenticat
我有一个查询,它根据用户的输入过滤电影,我需要添加一个limit作为查询参数,这样它就限制了电影返回的数量,如何添加它,我才刚刚开始编写雄辩的查询。
查询
$films = Film
::when($request->input('first'), function ($query, $first) {
$query->whereHas('options', function ($query) use ($first) {
$query->where('first', $main);
});
})
我有以下结构
转
id
OrderPayment
id
turn_id
invoice_id
OrderInvoice
id
order_id
阶
id
取消
合并
我想要做的是获得OrderPayments,其中Order没有被取消,也没有合并
现在我依次有以下代码
class Turn{
public function orderPayments(){
return $this->hasMany('OrderPayment');
}
}
如何才能只获得与Order相关的付款?
->where('canceled
我有两个模型,用户和学校;他们都属于其中的许多人。我试图返回与登录用户相同的用户列表。
USER MODEL
public function school(){
return $this->belongsToMany(School::class, 'school_user');
}
SCHOOL MODEL
public function user(){
return $this->belongsToMany(User::class, 'school_user');
}
The Eloquent
大家好,我是个新手,在理解如何查询关系方面有点困难。我正在尝试用laravel做一个基本的restful api,有3个模型 class Book extends Model
{
public function author()
{
return $this->belongsTo(Author::class);
}
public function categories()
{
return $this->belongsToMany('App\Category', 'category