diff --git a/README.md b/README.md index c188f12..c346f35 100755 --- a/README.md +++ b/README.md @@ -135,6 +135,14 @@ If you do not fill **Title** (2nd parameter) column name is used instead. >**Note**: you can set default formatting function that is applied on **Title** (2nd parameter), by default this is set to [`ucfirst`](http://php.net/manual/en/function.ucfirst.php). +Also there is a blade extension for you to use **@sortableurl()** for get only url-path. + +```blade +@sortableurl('column') +``` + +`@sortableurl` has similar arguments like `@sortablelink`, but not using (2nd) and (4th) parameters! + ## Configuration in few words **Sortablelink** blade extension distinguishes between *types* (**numeric**, **amount** and **alpha**) and applies different class for each of them. diff --git a/src/ColumnSortable/ColumnSortableServiceProvider.php b/src/ColumnSortable/ColumnSortableServiceProvider.php index 75df40f..f98fb71 100755 --- a/src/ColumnSortable/ColumnSortableServiceProvider.php +++ b/src/ColumnSortable/ColumnSortableServiceProvider.php @@ -37,6 +37,12 @@ public function boot() return ""; }); + Blade::directive('sortableurl', function ($expression) { + $expression = ($expression[0] === '(') ? substr($expression, 1, -1) : $expression; + + return ""; + }); + request()->macro('allFilled', function (array $keys) { foreach ($keys as $key) { if ( ! $this->filled($key)) { diff --git a/src/ColumnSortable/SortableLink.php b/src/ColumnSortable/SortableLink.php index 8fb4d70..c018e0d 100644 --- a/src/ColumnSortable/SortableLink.php +++ b/src/ColumnSortable/SortableLink.php @@ -40,6 +40,31 @@ public static function render(array $parameters) return ''.htmlentities($title).$trailingTag; } + /** + * @param array $parameters + * @param bool $absolute + * + * @return \Illuminate\Contracts\Routing\UrlGenerator|string + * @throws \Kyslik\ColumnSortable\Exceptions\ColumnSortableException + */ + public static function url(array $parameters, $absolute = true) + { + list($sortColumn, $sortParameter, $title, $queryParameters, $anchorAttributes) = self::parseParameters($parameters); + $explodeResult = self::explodeSortParameter($parameters[0]); + + $sortColumn = (empty($explodeResult)) ? $parameters[0] : $explodeResult[1]; + $queryParameters = (isset($parameters[2]) && is_array($parameters[2])) ? $parameters[2] : []; + $anchorAttributes = (isset($parameters[3]) && is_array($parameters[3])) ? $parameters[3] : []; + + list($icon, $direction) = self::determineDirection($sortColumn, $sortParameter); + + $queryString = self::buildQueryString($queryParameters, $sortParameter, $direction); + + $urlPath = request()->path().'?'.$queryString; + + return $absolute ? url($urlPath) : $urlPath; + } + /** * @param array $parameters