How to hide fields in queries using eloquent laravel using Join method

1

Of a question, I was given a way to query with child objects using the Join of eloquent, The query is below:

$dados = Roda::join('veiculos', function($query) {
    $query->on('veiculos.id', '=', 'rodas.veiculo_id');
    $query->where('veiculo.cor', '=', 'vermelho');
})
->get();
But now I need to hide fields that come in the object, and I do not know how to do this using the Join model that is seen above, the code solves another problem, which I can not solve otherwise. Now I need to hide fields, how can I do it?

    
asked by anonymous 17.10.2017 / 14:12

1 answer

3

You can use the select method by passing a array parameter to the name of the fields you want return.

$dados = Roda::join('veiculos', function($query) {
    $query->on('veiculos.id', '=', 'rodas.veiculo_id');
    $query->where('veiculo.cor', '=', 'vermelho');
})
->select(['rodas.cor', 'rodas.modelo'])
->get();

select() documentation

    
17.10.2017 / 14:23