Support the ongoing development of →
Eloquent Laravel
Last updated by @spawn2k 1 week 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');


Solution selected by @spawn2k

thx for the reply :D


Sign in to participate in this thread!

Full Stack Europe

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.

© 2023 - All rights reserved.