Package Data | |
---|---|
Maintainer Username: | Sukohi |
Maintainer Contact: | capilano.sukohi@gmail.com (Sukohi) |
Package Create Date: | 2014-10-15 |
Package Last Update: | 2017-01-30 |
Home Page: | |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2024-11-22 15:00:04 |
Package Statistics | |
---|---|
Total Downloads: | 12,287 |
Monthly Downloads: | 83 |
Daily Downloads: | 2 |
Total Stars: | 0 |
Total Watchers: | 2 |
Total Forks: | 0 |
Total Open Issues: | 0 |
A PHP package mainly developed for Laravel to manage sort values of DB table automatically.
(This is for Laravel 5+. For Laravel 4.2)
Add this package name in composer.json
"require": {
"sukohi/cahen": "2.*"
}
Execute composer command.
composer update
Register the service provider in app.php
'providers' => [
...Others...,
Sukohi\Cahen\CahenServiceProvider::class,
]
Also alias
'aliases' => [
...Others...,
'Cahen' => Sukohi\Cahen\Facades\Cahen::class
]
Basic
$model = YourModel::find(1);
\Cahen::move($model)->to('your-column-name', 5);
Up
\Cahen::move($model)->up('your-column-name');
Down
\Cahen::move($model)->down('your-column-name');
to First
\Cahen::move($model)->first('your-column-name');
to Last
\Cahen::move($model)->last('your-column-name');
with Transaction
\DB::beginTransaction();
if(!\Cahen::move($model)->to('your-column-name', 5)) {
\DB::rollback();
}
\DB::commit();
with Where Clause
You can use where
clause to sort within specific record(s).
$model = YourModel::find(1);
\Cahen::move($model)
->where('column_1', '=', 'value')
->where('column_2', 'LIKE', '%value%')
->to('your-column-name', 5);
Set data
You can sort within specific record(s) by setting model object.
$moving_id = 1;
$model = YourModel::find($moving_id);
$models = YourModel::where('id', '<', 5)
->where('id', '<>', $moving_id)
->get();
\Cahen::move($model)
->data($models)
->to('your-column-name', 3);
Alignment
$model = YourModel::orderBy('id', 'ASC')->get();
\Cahen::align($model, 'your-column-name');
About Sort Number
The sort value starts from 0.
This package is licensed under the MIT License.
Copyright 2014 Sukohi Kuhoh