4 weeks ago

Simplify Eloquent Code

Posted 4 weeks ago by ethar

in StudentCourse Model table (Pivot Table) i store('active_courses_id','student_id'),

In ActiveCourse i store (id,course_id)

in below query, I want to get all courses not registred to the user ($id),

I use two query, first to get activeCourse that user enrolls on it, then other query go get courses user did not enroll on it depend on the first query.

$courses = ActiveCourse::select('id', 'course_id')
   ->where('active', 1)

i want to ask if any way to use one query instead of two query

Please sign in or create an account to participate in this conversation.