At the very beginnings , i want to ask how to build a relation with many to many->many to many with custom key. I know that there is instruction with [
class User extends Model
{
use \Staudenmeir\EloquentHasManyDeep\HasRelationships;
public function permissions()
{
return $this->hasManyDeep('App\Permission', ['role_user', 'App\Role', 'permission_role']);
}
}
] But it does not has custom key . I want to know the full version.
Also , i have another another problems with the following models.
I want to create the following relationship. but i dont know how to do.
Product ----->belongs To (from_port_id)------> LogisticPort ----->belongs To many(to_port_id) ---->LogistoPort
Also,
With an Order belongsTo Many Products, Order Belongs To Port with 'to_port_id' ,Order Belongs To Logistic with 'logistic_id', Product belongs To Port with 'from_port_id',
from_port_id , to_port_id ,logistic_id and unit_price combined with a pivot table .
And now I want to ask. How to retrieve an order with different products with corresponding from_port_id,to_port_id,logistic_id to get different unit_price with the eager load as little sql as possible?
Order Model
+--------------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-----------+----------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| to_port_id | int(11) | NO | | NULL | |
| logistic_id | int(11) | NO | | NULL | |
+--------------+-------------+------+-----+---------+----------------+
Product Model
+--------------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-----------+----------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| from_port_id | int(11) | NO | | NULL | |
+--------------+-------------+------+-----+---------+----------------+
LogisticPort PivotModel
+--------------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+--------------+-------------+------+-----+---------+----------------+
| from_port_id | int(11) | NO | PRI | NULL | |
| to_port_id | int(11) | NO | PRI | NULL | |
| logistic_id | int(11) | NO | PRI | NULL | |
| unit_price | decimal(11) | NO | | NULL | |
+--------------+-------------+------+-----+---------+----------------+
At the very beginnings , i want to ask how to build a relation with many to many->many to many with custom key. I know that there is instruction with [ class User extends Model { use \Staudenmeir\EloquentHasManyDeep\HasRelationships;
} ] But it does not has custom key . I want to know the full version.
Also , i have another another problems with the following models. I want to create the following relationship. but i dont know how to do. Product ----->belongs To (from_port_id)------> LogisticPort ----->belongs To many(to_port_id) ---->LogistoPort Also, With an
Order belongsTo Many Products
,Order Belongs To Port with 'to_port_id'
,Order Belongs To Logistic with 'logistic_id'
,Product belongs To Port with 'from_port_id'
,from_port_id , to_port_id ,logistic_id and unit_price
combined with a pivot table .And now I want to ask. How to retrieve an order with different products with corresponding
from_port_id,to_port_id,logistic_id
to get different unit_price with the eager load as little sql as possible?Order Model
Product Model
LogisticPort PivotModel