/** * Returns resources that are leasable. * * @param $string * @return mixed */ protected function findResources($string) { // Searching supports not just "fedora" as input, but also "fedora-2" and "fedora-22" $resources = Resource::like(DB::raw("CONCAT(os,'-',os_version)"), $string)->orderBy('os', 'asc')->orderBy('os_version', 'desc'); // Removing resources that are under active leases could be accomplished several ways: // - Table join (downside - if tables are big, joins might be slow) // - Performing filtering right in the PHP (downside - few lines of extra code) // - Using `not in ()` syntax within MySQL (golden middle in this case) $activeLeases = Lease::active()->select('resource_id')->get(); $resources = $resources->whereNotIn('id', $activeLeases)->get(); return $resources; }