Support the ongoing development of Laravel.io →
Eloquent Laravel
Last updated by @spawn2k 1 year 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

spawn2k, salahedarhri liked this reply

2
Solution selected by @spawn2k

thx for the reply :D

salahedarhri liked this reply

1

Sign in to participate in this thread!

Eventy

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.

© 2024 Laravel.io - All rights reserved.