| Package Data | |
|---|---|
| Maintainer Username: | Rukhsar |
| Maintainer Contact: | rukhsar.man@gmail.com (Rukhsar Manzoor) |
| Package Create Date: | 2016-11-30 |
| Package Last Update: | 2016-11-30 |
| Language: | PHP |
| License: | MIT |
| Last Refreshed: | 2025-11-04 15:01:28 |
| Package Statistics | |
|---|---|
| Total Downloads: | 8 |
| Monthly Downloads: | 0 |
| Daily Downloads: | 0 |
| Total Stars: | 0 |
| Total Watchers: | 1 |
| Total Forks: | 0 |
| Total Open Issues: | 0 |
Collection of useful Laravel model traits to retrieve random model and add OrderBy functionality.
Require this package by running:
composer require rukhsar/addontraits
Usage
Add support for a standard order by
use Rukhsar\AddonTraits\OrderByTrait;
class User extends Model
{
use OrderByTrait;
protected $default_order_by = 'name';
protected $default_order_direction = 'asc';
}
Use Order() in your query to fetch the result.
$users = App\User::Order()->get();
You can select any column to add OrderBy functionality either in asc or desc order.
Laravel package for getting a random model from database.
Usage
Use RandomModelTrait in your model.
use Rukhsar\AddonTraits\RandomModelTrait;
class User extends Model
{
use RandomModelTrait;
}
Now you can use random() scope on your model.
$randomUser = User::random()->first();
$randomUserWithRelation = User::random()->with('relation_name')->first();
// Static methods which return an instance
$user = User::getRandom(); // return instance or null
$user = User::getRandomOrFail(); // return instance or throw exception