how to call model relation in which there is model relation in Laravel

  laravel, php, relation

#ask
How do you call the relation and its sub-relations in the model?
I made an AdditionalInformation model in which there is a relationship with telephone and additional data, and I want to call the AdditionalInformation model and its relationship in the ApplicationCloseGarden model

I want relation model AdditionalInformation with its relation
public function additionalInfo() { return $this->belongsToMany(AdditionalInformation::class, 'additional_informations_id', 'id'); }
and this model who should call


namespace AppModels;

use IlluminateDatabaseEloquentFactoriesHasFactory;
use IlluminateDatabaseEloquentModel;
use IlluminateDatabaseEloquentSoftDeletes;

class AdditionalInformation extends Model
{
    use HasFactory, SoftDeletes;

    protected $fillable = [
        'name',
        'bhirt',
        'identity',
        'address',
        'telephone_data_gardens_id',
        'npwp',
        'nationality',
        'payment_source',
        'customer_type',
        'additional_data_id',
    ];

    public function telephone()
    {
        return $this->belongsTo(TelephoneDataGarden::class, 'telephone_data_gardens_id', 'id');
    }
    
    public function additional()
    {
        return $this->belongsTo(AdditionalData::class, 'additional_data_id', 'id');
    }
}```

Source: Laravel

Leave a Reply