Laravel 5.5: Get name of each table in select union

1

I need to make a select in two tables and join them with union , until then, but I need to also get the name of the two so I can identify it in View . >

I have tried to use getTable() in each select , but it returns the error:

  

Non-static method Illuminate\Database\Eloquent\Model::getTable() should not be called statically

I also tried to get right into select , since I've done it this way once without using Laravel : select('tabela1 as table') and it returns a syntax error.

What is the right way to do this?

Code:

$first = Lista::where('serie_id', $serie->id)
        ->select('descricao as result1');

$atividades = Avaliar::where('serie_id', $serie->id)
        ->select('nota as result1')
        ->union($first)
        ->get();
    
asked by anonymous 23.12.2017 / 22:37

1 answer

1

$first = Lista::where('serie_id', $serie->id)
        ->select('descricao as result1')
        ->selectRaw("'Lista' as tabela");

$atividades = Avaliar::where('serie_id', $serie->id)
        ->select('nota as result1')
        ->selectRaw("'Avaliar' as tabela");
        ->union($first)            
        ->get();
    
23.12.2017 / 23:23