Download the PHP package qlick/column-sortable without Composer

On this page you can find all versions of the php package qlick/column-sortable. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package column-sortable

Column sorting for Laravel 5.5-8

Latest Version Total Downloads run-tests

Package for handling column sorting in Laravel 5.[5-8]. For earlier versions of Laravel checkout branch L5.1-3

Setup

Composer

Pull this package in through Composer (development/latest version dev-master)

Laravel's >=5.5 auto discovery

Simply install the package and let Laravel do its magic.

Note (pre Laravel 6.0): : major and minor versions should match with Laravel's version, for example if you are using Laravel 5.4, column-sortable version should be 5.4.*.

Manual installation (pre 5.5)

Add the service provider to array of providers in config/app.php

Publish configuration

Publish the package configuration file to your application.

See configuration file (config/columnsortable.php) yourself and make adjustments as you wish.

Usage

Use Sortable trait inside your Eloquent model(s). Define $sortable array (see example code below).

Note: Scheme::hasColumn() is run only when $sortable is not defined - less DB hits per request.

You're set to go.

Sortable trait adds Sortable scope to the models so you can use it with paginate.

Blade Extension

There is a blade extension for you to use @sortablelink()

Column (1st) parameter is column in database, Title (2nd) parameter is displayed inside anchor tags, array() parameter (3rd) is default (GET) query strings parameter and array() parameter (4th) is for additional anchor-tag attributes. You can use a custom URL as 'href' attribute in the 4th parameter, and the query string will be appended to it.

You can omit 2nd, 3rd and 4th parameter.

Possible examples and usages of blade extension:

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.

Configuration in few words

Sortablelink blade extension distinguishes between types (numeric, amount and alpha) and applies different class for each of them.

See following snippet:

Rest of the config file should be crystal clear and I advise you to skim it.

Font Awesome (default font classes)

Install Font-Awesome for visual Joy. Search "sort" in cheatsheet and see used icons (12) yourself.

Font Awesome 5

Change the suffix class in the config file from -asc/-desc (FA 4) to -up/-down (FA 5) respectively.

Note: If you haven't published the config yet, follow the instructions above.

Full Example

You may be interested in working example repository, where package usage is demonstrated.

Routes

Controller's index() method

You can set default sorting parameters which will be applied when URL is empty.

For example: page is loaded for first time, default direction is configurable (asc)

View (pagination included)

Note: Blade's ability to recognize directives depends on having space before directive itself <tr> @sortablelink('Name')

HasOne / BelongsTo Relation sorting

Define hasOne relation

In order to make relation sorting work, you have to define hasOne() relation in your model.

Define belongsTo relation

Note: in case there is a self-referencing model (like comments, categories etc.); parent table will be aliased with parent_ string, for more information see issue #60.

In User model we define hasOne relation to UserDetail model (which holds phone number and address details).

Define $sortable arrays

Define $sortable array in both models (else, package uses Scheme::hasColumn() which is an extra database query).

for User

for UserDetail

Blade and relation sorting

In order to tell package to sort using relation:

Note: package works with relation "name" (method) that you define in model instead of table name.

WARNING: do not use combination of two different relations at the same time, you are going to get errors that relation is not defined

In config file you can set your own separator in case . (dot) is not what you want.

ColumnSortable overriding (advanced)

It is possible to override ColumnSortable relation feature, basically you can write your own join(s) / queries and apply orderBy() manually.

See example:

Controller is the same $users = $user->sortable()->paginate(10);

In view just use @sortablelink('address')

Huge thanks to @neutralrockets and his comments on #8. Another example on how to use overriding is issue #41.

Aliasing

It is possible to declare $sortableAs array and use it to alias (bypass column exists check), and ignore prefixing with table.

In model

In controller

In view

See #44 for more information on aliasing.

Using withCount()

Aliasing is useful when you want to sort results with withCount(), see issue #49 for more information.

Exception to catch

Package throws custom exception ColumnSortableException with three codes (0, 1, 2).

Code 0 means that explode() fails to explode URI parameter "sort" in to two values. For example: sort=detail..phone_number - produces array with size of 3, which causes package to throw exception with code 0.

Code 1 means that $query->getRelation() method fails, that means when relation name is invalid (does not exists, is not declared in model).

Code 2 means that provided relation through sort argument is not instance of hasOne.

Example how to catch:

Note: I strongly recommend to catch ColumnSortableException because there is a user input in question (GET parameter) and any user can modify it in such way that package throws ColumnSortableException with code 0.


All versions of column-sortable with dependencies

PHP Build Version
Package Version
Requires php Version ^8.1
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package qlick/column-sortable contains the following files

Loading the files please wait ....