Basically, you first want to check the input has the data you're looking for, if it does, try to process/validate it, if it validates, then use it in your query.
// Get the query builder instance for the model
$query = Model::query();
if (Input::has('start_at'))
{
try {
$start_at = Carbon::createFromFormat('d/m/Y', Input::get('start_at'));
} catch(Exception $e) {
// Carbon failed to process input
}
if (isset($start_at))
{
$query->where('created_at', '>=', $start_at);
}
}
if (Input::has('end_at'))
{
try {
$end_at = Carbon::createFromFormat('d/m/Y', Input::get('end_at'));
} catch(Exception $e) {
// Carbon failed to process input
}
if (isset($end_at))
{
$query->where('created_at', '<=', $end_at);
}
}
$results = $query->get();
hi iWader, thank you for the replay
I've 4 input that could affect the query, like if the date is isset and name is isset, then i will want to query the date between which has name of someone. In more deep i will have date between, name and instructor. I will have these in one page to see the result :
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community