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.
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.
mubassirhayat liked this reply
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community