Вы можете определить объединение как построитель запросов для этой таблицы. Например:
$yachtdetail = DB::table("yachtdetail")
->select('authid', 'firstname', 'lastname');
$talentdetails = DB::table('talentdetails')
->select('authid', 'firstname', 'lastname');
Теперь вы можете использовать как:
$data = DB::table('service_request_reviews as srr')
->select('srr.id','srr.created_at','srr.fromid','srr.toid','srr.from_usertype','au.firstname_admin','au.lastname_admin','cd.name as to_compayname')
->leftjoin('auths as au', 'au.id', '=' ,'srr.fromid')
->leftjoin('companydetails as cd', 'cd.authid', '=', 'srr.toid')
->where('srr.isdeleted', '0')
->where('srr.parent_id', '0')
->union($yachtdetail)
->union($talentdetails)
->get();
Вот ссылка на документацию. https://laravel.com/docs/5.8/queries#unions
Отредактировано:
В вашем случае вы можете попробовать что-то вроде этого:
$queryBuilder = DB::table('service_request_reviews as srr')
->select('srr.id','srr.created_at','srr.fromid','srr.toid','srr.from_usertype','au.firstname_admin','au.lastname_admin','cd.name as to_compayname')
->leftjoin('auths as au', 'au.id', '=' ,'srr.fromid')
->leftjoin('companydetails as cd', 'cd.authid', '=', 'srr.toid')
->leftjoin(DB::raw("((select authid, firstname, lastname from userdetails)
union (select authid, firstname, lastname from yachtdetail)
union (select authid, firstname, lastname from talentdetails)
union (select authid, name as firstname, null as lastname from companydetails)) as unionSub1"), function($join){
$join->on(DB::raw('unionSub1.authid'), '=', DB::raw('srr.fromid'));
})
->where('srr.isdeleted', '0')
->where('srr.parent_id', '0');
$data = $queryBuilder->get();