1 year ago

Not sure which relationship to use

Posted 1 year ago by Danieloplata

Hi, I'm trying to link up two of my models in my project. Here's a simplified look at how it's working:


public function panels()
    return $this->hasMany(Panel::class);


public function project()
    return $this->belongsTo(Project::class);

public function provider()
    return $this->hasOne(Provider::class);

So every panel needs a provider, the same provider could be used by many panels.

The way I've got it set up, is my Panels table has a provider_id, but using the above code, eloquent tries to look in the Providers table for a panel_id.

So, my project->panel relationship works fine, but my panel->provider relationship seems backwards, I think I'm using the wrong type of relationship.

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