2017 © Pedro Peláez
 

library larasort

A PHP package mainly developed for Laravel to generate sort link(s).

image

monaye/larasort

A PHP package mainly developed for Laravel to generate sort link(s).

  • Sunday, February 25, 2018
  • by monaye
  • Repository
  • 1 Watchers
  • 1 Stars
  • 22 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 2 Forks
  • 0 Open issues
  • 7 Versions
  • 16 % Grown

The README.md

Larasort

A PHP package mainly developed for Laravel to generate sort link(s)., (*1)

alt text alt text, (*2)

Installation

Add this package name in composer.json, (*3)

"require": {
  "monaye/larasort": "2.*"
}

Execute composer command., (*4)

composer update

Register the service provider in app.php, (*5)

'providers' => [
    ...Others...,  
    Monaye\Larasort\LarasortServiceProvider::class,
]

Also alias, (*6)

'aliases' => [
    ...Others...,  
    'Larasort'   => Monaye\Larasort\Facades\Larasort::class
]

Usage

Minimal way, (*7)

{{ \Larasort::links('your-column-name') }}

(example)
alt text, (*8)

with Options, (*9)

echo \Larasort::url('http://example.com')  
    ->text('↑', '↓')  
    ->appends([
        'key1' => 'value1',  
        'key2' => 'value2',  
        'key3' => 'value3'  
    ])
    ->keys('order', 'direction')
    ->links('column_name', $separator = ''); 
  • All methods except links() are optional. See methods

Single Text Way, (*10)

If you set the third argument like the below, only one link will be displayed., (*11)

\Larasort::text(
    '<i class="fa fa-sort-asc"></i>',  
    '<i class="fa fa-sort-desc"></i>',  
    '<i class="fa fa-sort"></i>'
);

(example), (*12)

alt text, (*13)

Sort with model
With model(Eloquent), you can automatically set "ORDER BY" like the below., (*14)

$items = \App\Item::select('id', 'title');
$items = \Larasort::sort($items, 
    ['id', 'title', 'created_at'], 
    ['updated_at', 'asc']
);
dd($items->get()->toArray());
  • The second argument(Array) means that except specific column name(s) will be ignored to set "ORDER BY" for secure.
  • The third argument(Array) will be used for default. And direction canbe asc and desc

Note: If you changed the parameter name "ORDER BY" to other using keys() method, you also need to set it in this case as well., (*15)

Methods

  • url($url)

$url is base URL that will be included in href property., (*16)

  • text($one, $two)

$one and $two are text that will be included in link tag., (*17)

e.g. <a href="****">YOUR-TEXT</a>, (*18)

  • appends($values)

$values is additional values that you want to include in link URL., (*19)

e.g. http://example.com?orderby=*****&direction=asc&YOUR-KEY=YOUR-VALUE, (*20)

License

This package is licensed under the MIT License., (*21)

Copyright 2014 Monaye Kuhoh, (*22)

The Versions

25/02 2018

dev-master

9999999-dev

A PHP package mainly developed for Laravel to generate sort link(s).

  Sources   Download

MIT

The Requires

 

by Monaye Win

19/08 2015

1.0.x-dev

1.0.9999999.9999999-dev

A PHP package mainly developed for Laravel to generate sort link(s).

  Sources   Download

The Requires

 

by Avatar Sukohi

19/08 2015

1.0.1

1.0.1.0

A PHP package mainly developed for Laravel to generate sort link(s).

  Sources   Download

The Requires

 

by Avatar Sukohi

16/08 2015

2.0.x-dev

2.0.9999999.9999999-dev

A PHP package mainly developed for Laravel to generate sort link(s).

  Sources   Download

MIT

The Requires

 

by Avatar Sukohi

16/08 2015

2.0.1

2.0.1.0

A PHP package mainly developed for Laravel to generate sort link(s).

  Sources   Download

MIT

The Requires

 

by Avatar Sukohi

16/08 2015

2.0.0

2.0.0.0

A PHP package mainly developed for Laravel to generate sort link(s).

  Sources   Download

MIT

The Requires

 

by Avatar Sukohi

16/08 2015

1.0.0

1.0.0.0

A PHP package mainly developed for Laravel to generate sort link(s).

  Sources   Download

The Requires

 

by Avatar Sukohi