Support the ongoing development of Laravel.io →
Laravel Eloquent
Last updated 1 year ago.
0

I have done this

/**
 * Get offer related to the request.
 */
public function offer()
{
    return $this->hasOne('App\Offer', 'request_id', 'id')->where('boss_id', $this->boss_id);
}

and

/**
 * Get offer related to the request.
 */
public function offer()
{
    return $this->hasOne('App\Offer', 'request_id', 'id')->where('boss_id', $this->getAttribute('boss_id'));
}

but had no luck.

If I need to implement something I can do that as well but I need someone to put me in the right direction.

0

Hi Sir Mubassir,

are you telling me

return $this->hasOne('App\Offer', 'request_id', 'id')->where('boss_id', $this->boss_id);

gives you an Offer with boss_id different from the Request 's boss_id ?

The only way I can image this happening is that you have a Request with a loaded Offer, e.g. somewhere in your code you call

$request->offer;

and after that change the boss_id of the Request . The Offer will remain unchanged and when you invoke

$request->offer;

afterwards you will get the same Offer . The database will not be queried again.

Could this be your use case?

Ask yourself why do you have boss_id in the Offer when you already have it in the Request to which it belongs.

Last updated 6 years ago.

mubassirhayat liked this reply

1

Sign in to participate in this thread!

Eventy

Your banner here too?

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.