Support the ongoing development of →
Eloquent Laravel
Last updated by @spawn2k 10 months ago.

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');


spawn2k, salahedarhri liked this reply

Solution selected by @spawn2k

thx for the reply :D

salahedarhri liked this reply


Sign in to participate in this thread!


Your banner here too?

spawn4k spawn2k Joined 21 May 2023


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

Your logo here?

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

© 2024 - All rights reserved.