Support the ongoing development of Laravel.io →
Input Database Eloquent
Last updated 2 years ago.
0

If sorted this now after advice on another forum.

Basically what I have done is to build the query before it gets to it:

$built_query = [];
            isset($lead_tutor) ? $built_query['lead_tutor'] = 'lead_tutor_id = ' . $lead_tutor . ' ' : null;
            isset($secondary_tutor) ? $built_query['secondary_tutor'] = 'secondary_tutors_id = ' . $secondary_tutor . ' ' : null;
            isset($location_id) ? $built_query['location'] = 'location_id = ' . $location_id : null;
            isset($lesson_id) ? $built_query['lesson'] = 'lesson_id = ' . $lesson_id : null;

            // Flatten the array so we can create a query and add the word ADD in between each element.
            $built_query = implode(" AND ", $built_query);

            // Run the query
            $current_events = Calendar::whereBetween('date_from', [$start_time, $end_time])->orderBy('date_from')->whereRaw($built_query)->with('lessons', 'leadtutor', 'secondarytutor')->get();
Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

T2theC t2thec Joined 5 Feb 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.