Last active
September 27, 2016 08:00
-
-
Save Oldenborg/6d74eb3b68840eb2c68f2ad2991aa220 to your computer and use it in GitHub Desktop.
Laravel - Get Model with specific relations
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$clinics = new Clinic; | |
if($request->modules) | |
{ | |
foreach($request->modules as $module) | |
{ | |
$clinics = $clinics->whereHas('modules', function ($query) use ($module) { | |
$query->where('modules.id',$module); | |
}); | |
} | |
} | |
if($request->services) | |
{ | |
foreach($request->services as $service) | |
{ | |
$clinics = $clinics->whereHas('services', function ($query) use ($service) { | |
$query->where('services.id',$service); | |
}); | |
} | |
} | |
$filteredClinics = $clinics->get(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment