0
I’m making an appointment with union
in Laravel.
$first = Friendship::selectRaw('id, userid, friendid, friendid as friend')
->where('userid', '=', $idUser)
->where('confirmed_friendship', '=', 1)
->whereHas('user_friends', function($where){
$where->where('suspended', '=', 0)->where('deleted', '=', 0);
});
$content = Friendship::selectRaw('id, userid, friendid, userid as friend')
->where('friendid', '=', $idUser)
->where('confirmed_friendship', '=', 1)
->whereHas('friends', function($where){
$where->where('suspended', '=', 0)->where('deleted', '=', 0);
})
->union($first);
$content = $content->get();
And I’d like to make a relationship with another table using the alias I put on SELECT
.
public function user_friends(){
// Gostaria de indicar aqui a coluna que eu renomeei para `friend`
return $this->belongsTo('App\User', 'friendid');
}
It is possible to do this?
I would like to make a relationship with another table is this is possible? Yes it is possible, but it could also
model
and which fields relate!– novic
I edited the question so that you and other users can better understand what I want.
– Diego Souza