Relationship with 3 tables

Posted 4 months ago by romulo27

I'm confusing a relationship with more than 3 tables. I have the DealershipStore,DealershipsStoreBrand and DealershipsStoreCategoryOptions models. As soon as I paste data into DealershipStore, I store that id in theDealershipsStoreBrand table and so on DealershipsStoreCategoryOptions, but for that I need a sync. The problem is failing to relate the sync between them.

class DealershipStore extends Model
{
    /**
     * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
     */
    public function dealershipStoreBrands(): BelongsToMany
    {
        return $this->belongsToMany(DealershipsStoreBrand::class);
            // ->with(BrandDealerships::class)
            // ->with(Brand::class);
    }
}
class DealershipsStoreBrand extends Model
{
    /**
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
     */
    public function dealershipStore()
    {
        return $this->belongsTo(DealershipStore::class);
    }

    /**
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
     */
    public function dealershipBrand()
    {
        return $this->belongsTo(BrandDealerships::class);
    }
}
class DealershipsStoreCategoryOptions extends Model
{
    /**
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
     */
    public function dealershipStoreBrand()
    {
        return $this->belongsTo(DealershipsStoreBrand::class);
    }

    public function brandStoreOption()
    {
        return $this->belongsTo(BrandStoreCategoryOption::class);
    }

}

Please sign in or create an account to participate in this conversation.