1
Good people, I have a form that should be filtering the selected fields looking for direct information in the database, however I do not know how to use the Where clause, can anyone here help me or give me a few tips? Grateful from now on.
Note: I can make the return of all the fields saved in the database, however I want to return only those that are selected in the form, those that are not want to come in white, I have the following:
$table = DB::table('projecao_despesa as ppadesp')
->join('unidade as unid', 'ppadesp.unidadeId', '=', 'unid.id')
->join('orgao', 'unid.orgaoId', '=', 'orgao.id')
->join('poder', 'orgao.poderId', '=', 'poder.id')
->join('funcao as func', 'ppadesp.funcaoId', '=', 'func.id')
->join('sub_funcao as subfunc', 'ppadesp.subfuncaoId', '=', 'subfunc.id')
->join('programa as prog', 'ppadesp.programaId', '=', 'prog.id')
->join('acao', 'ppadesp.acaoId', '=', 'acao.id')
->join('elemento as elem', 'ppadesp.elementoId', '=', 'elem.id')
->join('ppa', 'ppadesp.ppaId', '=', 'ppa.id')
->select('poder.nome as a', 'orgao.nome as b', 'unid.nome as c',
DB::raw("concat(func.funcao, '.', subfunc.subFuncao, '.', prog.programa, '.', acao.acao, '.', elem.elemento) as d"),
'ppa.anoInicio as e', 'ppadesp.valorAno1 as f', 'ppadesp.valorAno2 as g',
'ppadesp.valorAno3 as h', 'ppadesp.valorAno4 as i')
->orderby('ppadesp.id')->paginate(5);
$header = ['Poder', 'Orgão', 'Unidade', 'Funcional',
'Ano Inicial', 'Primeiro Ano', 'Segundo Ano', 'Terceiro Ano', 'Quarto Ano'];
return View('results.planejamento.ppa_despesa', ['header' => $header, 'table' => $table]);
what exactly do you want to filter? What fields?
– Marllon Nasser
Hello Lincon, To use Where simply add the Where method, ex. ->Where('power.name', '=', 'MPF'), and add the rest, the complete documentation can be found here -> https://laravel.com/docs/5.0/eloquent
– ooredroxoo
Thanks ooredroxoo, I will study on the subject, the tip was worth it, God bless you ! : D
– Lincoln Binda