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 |
A PHP package mainly developed for Laravel to generate sort link(s).
(This is for Laravel 5+. For Laravel 4.2)
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
]
Minimal way
{{ \Caruta::links('your-column-name') }}
(example)
with Options
echo \Caruta::url('http://example.com')
->text('↑', '↓')
->appends([
'key1' => 'value1',
'key2' => 'value2',
'key3' => 'value3'
])
->keys('order', 'direction')
->links('column_name', $separator = '');
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)
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());
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.
$url
is base URL that will be included in href
property.
$one
and $two
are text that will be included in link tag.
e.g. <a href="****">YOUR-TEXT</a>
$values
is additional values that you want to include in link URL.
e.g. http://example.com?orderby=*****&direction=asc&YOUR-KEY=YOUR-VALUE
This package is licensed under the MIT License.
Copyright 2014 Sukohi Kuhoh