How to create a dynamic query using eloquent How to create a dynamic query using eloquent:
sending an array of checkbox and need to use it in the where
//form
@foreach ($tipos as $tipo)
<input type="checkbox" name="estaciones[]" value="{{ $tipo->id }}" id="{{ $tipo->id }}">{{ $tipo->nombre }} <br>
@endforeach
Route::get('getEstaciones', function(){
$opciones = Input::get('info');
$list = Station::where('tipoestacion_id', '=', )->get();
return json_encode($list);
});
Query methods return a query object that is chainable.
$query = Station::select();
foreach($conditions as $column => $value)
{
$query->where($column, '=', $value);
}
$stationes = $query->get();
Note that you can use orWhere for a or clause. Note also that you can group where/orWhere clauses using a callback in a where/orWhere clause. Check the docs about that.
Or maybe :
$list = Station::whereIn('tipoestacion_id', Input::get('estaciones'))->get();
Please sign in or create an account to participate in this conversation.