Skip to content

Commit

Permalink
simplify the Laravel 5.1/5.2/Lumen stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
cviebrock committed Jun 8, 2016
1 parent b76d400 commit a402614
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 26 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -3,6 +3,7 @@
## 4.0.0 - xx-Jun-2016

- Fix for Laravel 5.1 (#263 thanks @roshangautam and @andregaldino).
- Update `Cocur\Slugify` to `^2.1` (#269 thanks @shadoWalker89).


## 4.0.0-beta - 01-Jun-2016
Expand Down
31 changes: 5 additions & 26 deletions src/Services/SlugService.php
Expand Up @@ -318,13 +318,11 @@ protected function getExistingSlugs($slug, $attribute, array $config)
}

// get the list of all matching slugs
// (need to do this check because of changes in Query Builder between 5.1 and 5.2)
// @todo refactor this to universally working code
if (version_compare($this->getApplicationVersion(), '5.2', '>=')) {
return $query->pluck($attribute, $this->model->getKeyName());
} else {
return $query->lists($attribute, $this->model->getKeyName());
}
$results = $query->addSelect([$attribute, $this->model->getKeyName()])
->get();

// key the results and return
return $results->pluck($attribute, $this->model->getKeyName());
}

/**
Expand Down Expand Up @@ -374,23 +372,4 @@ public function setModel(Model $model)

return $this;
}

/**
* Determine the version of Laravel (or the Illuminate components) that we are running.
*
* @return string
*/
protected function getApplicationVersion()
{
static $version;

if (!$version) {
$version = app()->version();
// parse out Lumen version
if (preg_match('/Lumen \((.*?)\)/i', $version, $matches)) {
$version = $matches[1];
}
}
return $version;
}
}

0 comments on commit a402614

Please sign in to comment.