SUKOHI / Caruta by Sukohi

A PHP package mainly developed for Laravel to generate sort link(s).
346
2
2
Package Data
Maintainer Username: Sukohi
Maintainer Contact: capilano.sukohi@gmail.com (Sukohi)
Package Create Date: 2014-09-30
Package Last Update: 2015-08-19
Language: PHP
License: Unknown
Last Refreshed: 2024-11-19 03:18:29
Package Statistics
Total Downloads: 346
Monthly Downloads: 1
Daily Downloads: 0
Total Stars: 2
Total Watchers: 2
Total Forks: 2
Total Open Issues: 0

Caruta

A PHP package mainly developed for Laravel to generate sort link(s).
(This is for Laravel 5+. For Laravel 4.2)

alt text alt text

Installation

Add this package name in composer.json

"require": {
  "sukohi/caruta": "2.*"
}

Execute composer command.

composer update

Register the service provider in app.php

'providers' => [
    ...Others...,  
    Sukohi\Caruta\CarutaServiceProvider::class,
]

Also alias

'aliases' => [
    ...Others...,  
    'Caruta'   => Sukohi\Caruta\Facades\Caruta::class
]

Usage

Minimal way

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

(example)
alt text

with Options

echo \Caruta::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

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

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

(example)

alt text

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

$items = \App\Item::select('id', 'title');
$items = \Caruta::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.

Methods

  • url($url)

$url is base URL that will be included in href property.

  • text($one, $two)

$one and $two are text that will be included in link tag.

e.g. <a href="****">YOUR-TEXT</a>

  • appends($values)

$values is additional values that you want to include in link URL.

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

License

This package is licensed under the MIT License.

Copyright 2014 Sukohi Kuhoh