我有三张桌子
Company->ManyToMany->Activity->BelongsTo->chamber
我需要使用HasmanyDeep找到所有与特定公司相关的商会。当我用公司模型编写它时,它返回为空
public function chambers(){
return $this->hasManyDeep('App\Models\Chamber',['activity_company','App\Models\Activity'],['activity_id','comp
我跟父母和他们的孩子有个安排。一个子节点可以有多个父级,每个子级可以由系统分配多个消息。每个家长也可以有多个孩子。
我已经有了一个用户实例:$parent。现在我想收到所有属于这个家长的孩子的帖子。拉勒维尔的“有很多贯穿”并不适用于多到多的关系。
目前,我用自定义方法解决了这个问题,但是我正在寻找更干净的方法来解决这个问题。
这是我的设计:
用户(父母)
class User extends Eloquent
{
public function children()
{
return $this->belongsToMany('Child'
我在做一个复杂的购物车项目。我有这样的关系
CategoryGroup模型
// App\CategoryGroup
class CategoryGroup extend Model
{
public function categories()
{
return $this->hasMany(Category::class);
}
}
范畴模型
// App\Category
class Inventory extend Model
{
public function categoryGroup()
{
我有三个模型:
Product
Inventory
Order
它们之间的关系如下:
订单与存货和$nventory->belongsTo(‘manyToMany’)有产品关系;
/** Product Model **/
class Product extend Model
{
public function inventories()
{
return $this->hasMany('App\Inventory');
}
}
/** Inventory Model **/
class Inventory extend
我有以下使用Laravel5.3的模型:
提供商:
// Provider model
$primaryKey = 'id'
public function activities()
{
return $this->hasMany(Activity::class);
}
活动:
// Activity model
$primaryKey = 'id'
public function provider()
{
return $this-belongsTo(Provider::class);
}
public function sem
我正在尝试在Laravel上构建一个应用程序,其中包含以下模型: type
id - integer
name - string
companies
id - integer
name - string
type_id - integer
contacts
id - integer
name - string
company_contact
contact_id - integer
company_id - integer Contact到Company是many to many关系,company_contact
我有客户端,有用户,有多到多表的调查。所以user_surveys。
我想知道怎样才能把一些关系说得很深。我想统计一下用户为那个客户做的所有调查。
我试过的
Client.php
public function countSurveys()
{
$employees = $this->employees;
// this returns Property [surveys] does not exist on this collection instance.
return $employees->surveys->count();
我正在构建一个新的laravel应用程序,用户可以有多个角色,这些角色具有多个权限(permissions).现在,我想从某个用户那里获得所有权限。
我用的是Laravel5.8和雄辩。我可以从用户获得角色,从角色获得权限,但不能从用户获得权限。
dd(Auth::user()->roles->rights);
模型用户:
public function roles()
{
return $this->belongsToMany(Role::class);
}
模范角色:
public function users()
我有很多模特儿的关系就像。我想通过枢轴表将State和联系起来。
范畴模型
class Category extends Model
{
public function news() {
return $this->belongsToMany('App\News');
}
}
新闻模型
class News extends Model
{
public function categories()
{
return $this->belongsToMany('
这是我的投票模式:
namespace App;
use Illuminate\Database\Eloquent\Model;
class Vote extends Model
{
public function user(){
return $this->belongsTo('App\User');
}
public function options(){
return $this->hasMany('App\Option');
}
}
这是我的选择模式:
namespace App;
我有以下几种型号:
User:
- id
- name
Location:
- id
- name
- region_id
table: user_location
- user_id
_ location_id
通过该表的用户belongsToMany位置。我还有另一种模式:
Region
- id
- name
我定义了区域hasMany位置。
有了这些关系,我如何定义用户和区域之间的关系--哪个区域将能够找到与其相关的所有位置下的所有用户?
<?php
class User extends Model
{
public function locations() {
我有四张桌子,
道具,列表,提议,联系
道具有很多列表,列表属于道具。
公共函数列表(){返回$this->hasMany('App\Models\Listing\Listing');}
要约属于上市,
public function property()
{
return $this->belongsTo('App\Models\Property\Property')->with('owners');
}
然后提供belongsToMany接触槽offer_contact表
public function bu
我在我的PHP应用程序中使用了Eloquent,并且在处理hasManyThrough关系时遇到了困难。
这是我的结构:
Company
id
name
Admin
id
company_id
name
Offer
id
admin_id
name
Application
id
offer_id
candidat_id
每个Admin都是Company的一部分,可以发布Offer,而候选人可以根据该提议做出Application。
我正在尝试获取该公司管理员提供的所有应用程序。。
我尝试在我的hasManyThrough
我有一个Subscriber模型
// Subscriber Model
id
user_id
subscribable_id
subscribable_type
public function user()
{
return $this->belongsTo('App\User');
}
public function subscribable()
{
return $this->morphTo();
}
和Topic模型
// Topic Model
public function subscribers()
{
return $
我有以下几种型号:
Product
BaseProduct
BaseCode
Series
它们中的每一个都是一个独立的实体,但它们是相互关联的。
Product有BaseProduct的外键,BaseProduct有BaseCode的外键,BaseCode有Series的外键。
我已经在BaseCode模型中指定了一个方法,这样我就可以选择与特定BaseCode相关的所有Products。
public function Products()
{
return $this->hasManyThrough('Product', 'BaseProduct
我对拉里威尔的ORM提出了一个问题,口才很强,至今还没有找到解决办法。
我有几张桌子如下
Team
- id
- name
用户
- id
- name
- role
- team_id
Student_Info
- id
- user_id
- data1
- data2
- etc ...
项目
- id
- student_id
- name
现在,我想查询所有项目--一个特定的team,其中team = 'some team'
现在的问题是,如果没有ORM,它很简单,我会在原始SQL中进行多个联接。
但是,因为所有这些表都有一个公共列"
在我的Laravel应用程序中,我有以下类:
class Product extends Model
{
public function extended()
{
return $this->morphTo();
}
public function users {
return $this->belongsToMany('App\User', 'products_users', 'product_id');
}
}
class Foo extends Mode
我创建了一个这样的关系:
Type.City.Street.House.Apartment
在此关系中,公寓必须同时依赖于房屋和类型,因此结果sql查询必须如下所示:
select * from `apartments` where `apartments`.`house_id` in ('1', '2', '3') and `type_id` = '777'
问题是,HasManyThrough关系只看了两个层次,不可能得到第一个模型。
请告诉我如何做到这一点?
我的模型定义:
class Type extends Model
在我的网站上,我有用户,角色和权限。
每个用户属于多个角色(例如,User.php)和名为'role_user‘的数据透视表
public function roles()
{
return $this->belongsToMany(Role::class);
}
并且每个角色都属于许多权限(例如,Role.php)和名为'permission_role‘的数据透视表
public function permissions()
{
return $this->belongsToMany(Permission::class);
}
我想以某种方式访问用