Support the ongoing development of Laravel.io →
Eloquent Laravel
Last updated by @spawn2k 1 week ago.
0
Solution

Hello @spawn2k,

As also mentioned in the stack overflow post you need to explicitly define your local and foreign key in both the relationships because you are not using the default id column for referencing.

So, your relationships should be defined as:

on the PizzaPrice model

public function pizza(): BelongsTo
{
    return $this->belongsTo(Pizza::class, 'pizza_id','pizza_id');
}

on the pizzas model

public function pizzaPrice(): HasOne
{
    return $this->hasOne(PizzaPrice::class, 'pizza_id','pizza_id');
}

Thanks

1
Solution selected by @spawn2k

thx for the reply :D

0

Sign in to participate in this thread!

Full Stack Europe

Your banner here too?

spawn4k spawn2k Joined 21 May 2023

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2023 Laravel.io - All rights reserved.