Feature #225
openFeature #217: [api] DANH MỤC - POST - PRODUCT
[api] #217 thêm model column relationship
0%
Description
e_visa_category_terms
e_visa_categories
e_visa_destinations
e_visa_post_categories
Updated by Redmine Admin 21 days ago
- Subject changed from [api] thêm model column relationship to [api] #217 thêm model column relationship
Updated by Redmine Admin 21 days ago · Edited
CategoryModel
public function posts()
{
return $this->belongsToMany(
PostModel::class,
TABLE_E_VISA_POST_CATEGORY,
'category_id',
'post_id'
)->wherePivot('type', 'post');
}
public function destinations()
{
return $this->belongsToMany(
DestinationModel::class,
TABLE_E_VISA_POST_CATEGORY,
'category_id',
'post_id'
)->wherePivot('type', 'destination');
}
PostModel
public function categories()
{
return $this->belongsToMany(
CategoryModel::class,
TABLE_E_VISA_POST_CATEGORY,
'post_id',
'category_id'
)
->wherePivot('type', 'post')
->withPivotValue('type', 'post');
}
Thêm DestinationMode.php
public function categories()
{
return $this->belongsToMany(
CategoryModel::class,
TABLE_E_VISA_POST_CATEGORY,
'post_id',
'category_id'
)
->wherePivot('type', 'destination')
->withPivotValue('type', 'destination');
}
public function country()
{
return $this->belongsTo(
CountryModel::class,
'country_id',
'id'
);
}
CountryModel
public function destinations()
{
return $this->hasMany(
DestinationModel::class,
'country_id',
'id'
);
}
public function destination($domain = 'EW')
{
return $this->hasOne(
DestinationModel::class,
'country_id',
'id'
)->where('domain', $domain);
}
cách dùng
$country->destination()->first();
$country->destination('EG')->first();