Relationship in Model with Column Name Alias

0

I'm doing a query 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 would like to make a relationship with another table using the alias I put in SELECT .

public function user_friends(){
    // Gostaria de indicar aqui a coluna que eu renomeei para 'friend'

    return $this->belongsTo('App\User', 'friendid');
}

Is it possible to do this?

    
asked by anonymous 01.08.2018 / 14:47

0 answers