dev-master
9999999-devA Rankable Eloquent Model Package
MIT
The Requires
- php >=5.3.0
- illuminate/support 4.0.x
- illuminate/database 4.0.x
by Ryan Tablada
orm laravel eloquent lpm rankable
Wallogit.com
2017 © Pedro Peláez
A Rankable Eloquent Model Package
This package makes rankable models for sorting quick and easy., (*1)
Making Rankable Models is just as easy as creating regular Eloquent Models with just one more property protected $metricsWeight!, (*2)
An example model would look something like this:, (*3)
use Rtablada\EloquentRankable\RankableModel;
class Friend extends RankableModel
{
protected $metricWeights = array(
'search' => 0.8,
'name' => 0.2
);
protected $fillable = array('name', 'rank');
}
In your Schema remember to include a rank column (I suggest using a Decimal fieldtype with a 10 digits and 4 decimals)., (*4)
$metricWeight PropertyThe $metricWeight property is an easy way to modify the ranking property of your models.
You can set weights for whenever you use an updateMetric* function., (*5)
So if you want to update a model's rank when you get a result in a search you could run $model->updateMetricSearch() which will raise the ranking by 0.8 points., (*6)
These updateMetric functions can also be used in mutators or accessors., (*7)
public function setNameAttribute($value)
{
$this->attributes['name'] = $value;
$this->updateMetricName();
}
Any time you want to get results already sorted descending by rank you can just prepend your wanted query builder function with rank.
For example:, (*8)
$friends = Friend::rankAll(); $friendsPaginated = Friend::rankPaginate();
The model also gives you the ability to rankBefore, rankBetween, or rankAfter another model instance., (*9)
$friendLow = Friend::find(1); $friendHigh = Friend::find(1); $friendLow->rankBefore($friendHigh);
ids
For uses such as Javascript Web Apps, Rankable gives you a quick and easy way to update the rankings between entries., (*10)
$desiredIds = array(1,2,3); $friends = Friend::rankOrderSet($desiredIds);
A Rankable Eloquent Model Package
MIT
orm laravel eloquent lpm rankable