Fixes API sorting and filtering. Closes #1489

This commit is contained in:
Joseph Cohen
2016-02-23 13:34:22 -06:00
committed by James Brooks
parent 98550c31c9
commit 919c7127e7
10 changed files with 136 additions and 14 deletions
+40
View File
@@ -0,0 +1,40 @@
<?php
/*
* This file is part of Cachet.
*
* (c) Alt Three Services Limited
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace CachetHQ\Cachet\Models\Traits;
use Illuminate\Database\Eloquent\Builder;
/**
* This is the sortable trait.
*
* @author James Brooks <james@alt-three.com>
*/
trait SortableTrait
{
/**
* Adds a sort scope.
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param string $column
* @param string $direction
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeSort(Builder $query, $column, $direction)
{
if (!in_array($column, $this->sortable)) {
return $query;
}
return $query->orderBy($column, $direction);
}
}