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-05-10 22:23:00 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.