|
@@ -15,7 +15,7 @@ use Spatie\EloquentSortable\Sortable;
|
|
|
*/
|
|
|
trait SortableTraitPinned
|
|
|
{
|
|
|
- public static function bootSortableTrait()
|
|
|
+ public static function bootSortableTraitPinned()
|
|
|
{
|
|
|
static::creating(function ($model) {
|
|
|
if ($model instanceof Sortable && $model->shouldSortWhenCreating()) {
|
|
@@ -111,7 +111,6 @@ trait SortableTraitPinned
|
|
|
$swapWithModel = $this->buildSortQuery()->limit(1)
|
|
|
->orderBy('is_pinned', 'desc')->orderBy('order', 'desc')
|
|
|
->where($orderColumnName, '<', $this->$orderColumnName)
|
|
|
- ->where('is_pinned', '=', $this->is_pinned)
|
|
|
->first();
|
|
|
|
|
|
if (! $swapWithModel) {
|
|
@@ -129,17 +128,14 @@ trait SortableTraitPinned
|
|
|
$orderColumnName = $this->determineOrderColumnName();
|
|
|
|
|
|
$swapWithModel = $this->buildSortQuery()->limit(1)
|
|
|
- ->orderBy('is_pinned', 'desc')->orderBy('order', 'asc')
|
|
|
+ ->orderBy('is_pinned', 'asc')->orderBy('order', 'asc')
|
|
|
->where($orderColumnName, '>', $this->$orderColumnName)
|
|
|
- ->where('is_pinned', '=', $this->is_pinned)
|
|
|
->first();
|
|
|
|
|
|
if (! $swapWithModel) {
|
|
|
return $this;
|
|
|
}
|
|
|
-// var_dump($this->is_pinned, $swapWithModel->is_pinned);
|
|
|
-// var_dump($this->id, $swapWithModel->id);
|
|
|
-// exit;
|
|
|
+
|
|
|
if (($this->is_pinned == 1 && $swapWithModel->is_pinned == 0)
|
|
|
|| ($this->is_pinned == 0 && $swapWithModel->is_pinned == 1)) {
|
|
|
throw new \Exception('No sorting allowed');
|