class Country extends Model
{
public function capitalCity(): HasOne
{
return $this->hasOne(City::class);
}
}
class City extends Model
{
public function country(): BelongsTo
{
return $this->belongsTo(Country::class);
}
public function mainDistrict(): HasOne
{
return $this->hasOne(\App\Models\District::class);
}
}
class District extends Model
{
protected function city(): BelongsTo
{
return $this->belongsTo(\App\Models\City::class);
}
}
class CountryResource extends Resource
{
public static function form(Form $form): Form
{
return $form
->schema([
TextInput::make('name')
->required(),
Section::make("Capital")->schema([
TextInput::make("name")->required(),
TextInput::make("zip")->required(),
Section::make("District")->schema([
TextInput::make("name")->required(),
])->relationship("mainDistrict")
])->relationship("capitalCity")
]);
}
}