Search code examples
laravellumenrelationhas-one

Laravel hasOne Relation 2 columns


I have 2 Models first one is(Plan) and the second is (PlanPrice)

I have this columns in table plan_price:

$table->float('price')->comment('Price for one month or one year depends on country code'); $table->string('country_code')->default('EG');

What I want is to get a plan with price depends on the user country code.


Solution

  • I think you should do this:

    return $this->hasOne(PlanPrice::class, 'plan_id')->where('country_code', 
    $what_ever_your_code_is);