How to hide fields in queries using eloquent Join method

Asked

Viewed 297 times

1

From a question, I was given a way to make queries with children objects using the Join of the eloquent, The query is below:

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

However, now the need arises 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, that can not solve otherwise. Now it appears I need to hide fields, How can I do?

1 answer

3


You can use the method select passing by parameter one array with the name of the fields you want to 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();

Documentation of select().

  • To close the question, I could provide the documentation where you are based to answer?

  • http://laravel.com/docs - it is possible to notice that when I speak in methods I put links to their documentation.

  • On what page? because I couldn’t find anything you taught me in both posts. It could be a little more specific?

  • Just use the search box. What do you need specification for? In both posts there are links to the exact pages that I consulted.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.