alex-kudrya/orderbyfield

SQL "ORDER BY FIELD()" function for Laravel query builder or model

v1.1 2023-12-08 20:16 UTC

This package is not auto-updated.

Last update: 2024-11-09 00:35:23 UTC


README

It is trait with scope function for Laravel applications

Installation

composer require alex-kudrya/orderbyfield

Usage

Example:

// app/Models/User.php

namespace App\Models;

use AlexKudrya\OrderByField\OrderByField;

class User extends Model
{
    use OrderByField;

    ...
}

Now you can use orderByField() method:


$ordered_list = User::orderByField('role_id', [4,2])->get();

Now in $ordered_list all users sorted in same order: first users with role_id = 4, second role_id = 2, and than rest of them.