У меня есть три реляционные таблицы ниже.
https://drive.google.com/file/d/1q1kdURIwFXxHb2MgdRyBkE1e3DMug7r-/view?usp=sharing
У меня также есть три отдельные модели, в которых определены отношения между всеми моими таблицами. Я могу прочитать информацию о модели города из модели страны, используя отношение hasManyThrough()
Но не могупрочитайте информацию о стране из модели города.Я пытался получить модель города, используя `` hasManyThrough```, но не получил результата (прикрепленный как метод страны с комментариями).Пожалуйста, прочитайте мою модель и ее реляционный метод здесь ..
Есть ли кто-нибудь, кто поможет мне получить информацию о модели города, используя метод Eloquent hasManyThrough / hasManyThrough
или обратный hasManyThrough / hasManyThrough
?
01.
<?php
namespace App\Hrm;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
class Country extends Model
{
//use SoftDeletes;
protected $fillable = ['name','description','status'];
public function districts(){
return $this->hasMany(District::class);
}
public function cities(){
return $this->hasManyThrough(City::class,District::class);
}
}
02.
<?php
namespace App\Hrm;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
class District extends Model
{
//use SoftDeletes;
protected $fillable = ['country_id','name','description','status'];
public function country(){
return $this->belongsTo(Country::class);
}
public function cities(){
return $this->hasMany(City::class);
}
}
3.
namespace App\Hrm;
use App\User;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
class City extends Model
{
//use SoftDeletes;
protected $fillable = ['district_id','name','description','status'];
public function district(){
return $this->belongsTo(District::class);
}
// public function country(){
// return $this->hasOneThrough(Country::class, District::class);
// }