PHP code example of c6digital / laravel-orderable
1. Go to this page and download the library: Download c6digital/laravel-orderable library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
c6digital / laravel-orderable example snippets
use C6Digital\Orderable\Concerns\Orderable;
use C6Digital\Orderable\Concerns\OrderableOptions;
class Post extends Model
{
use Orderable;
public static function getOrderableOptions(): OrderableOptions
{
return OrderableOptions::default()
->column('order') // Set the column that is used to order this model.
->reorderOnCreate() // Determine whether models should be re-ordered after creation.
->moveToEndOnCreate() // Place newly created models at the end.
->moveToStartOnCreate() // Place newly created models at the start.
->setOrderUsing(callback: ...); // Set the order manually using a custom callback.
}
}
Post::query()
->ordered() // Defaults to `ASC`.
->orderedAsc() // Orders `ASC`.
->orderedDesc() // Orders `DESC`.