Project

General

Profile

Actions

Feature #225

open

Feature #217: [api] DANH MỤC - POST - PRODUCT

[api] #217 thêm model column relationship

Added by Redmine Admin 21 days ago. Updated 21 days ago.

Status:
New
Priority:
Normal
Assignee:
-
Start date:
05/27/2026
Due date:
% Done:

0%

Estimated time:

Description

e_visa_category_terms
e_visa_categories
e_visa_destinations
e_visa_post_categories

Actions #1

Updated by Redmine Admin 21 days ago

  • Subject changed from [api] thêm model column relationship to [api] #217 thêm model column relationship
Actions #2

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();

Actions

Also available in: Atom PDF