1. Go to this page and download the library: Download plutuss/sortable-laravel 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/ */
plutuss / sortable-laravel example snippets
namespace App\Models;
use Plutuss\Sortable\Contracts\SortableInterface;
use Plutuss\Sortable\Traits\Sortable;
class Movie extends Model implements SortableInterface
{
use Sortable;
public function sortables(): array
{
return [
'views_desc', // field in database + SQL ORDER BY Keyword
or
'views_key' => [ // key any
'views', // field in database
'ASC', // SQL ORDER BY Keyword
],
];
}
namespace App\Http\Controllers;
use App\Models\Movie;
class MovieController extends Controller
{
/**
* @param Request $request
* @return Application|Factory|View
*/
public function index(Request $request)
{
$movies = Movie::sort()->paginate(12)
return view('movies.index', compact('movies'));
}