src/Repositories/EloquentRepository.php
public function adjacent($direction, $model, $category_id = null, array $with = [], $all = false)
    {
        $currentModel = $model;
        if ($category_id !== null) {
            $models = $this->with('category')->findWhere(['category_id', $category_id], ['id', 'category_id', 'slug']);
        } else {
            $models = $this->all(['id', 'slug']);
        }
        foreach ($models as $key => $model) {
            if ($currentModel->id == $model->id) {
                $adjacentKey = $key + $direction;

                return isset($models[$adjacentKey]) ? $models[$adjacentKey] : null;
            }
        }
    }
public function adjacent($direction, $model, $category_id = null, array $with = [], $all = false)
    {
        $currentModel = $model;
        if ($category_id !== null) {
            $models = $this->with('category')->findWhere(['category_id', $category_id], ['id', 'category_id', 'slug']);
        } else {
            $models = $this->all(['id', 'slug']);
        }
        foreach ($models as $key => $model) {
            if ($currentModel->id == $model->id) {
                $adjacentKey = $key + $direction;

                return isset($models[$adjacentKey]) ? $models[$adjacentKey] : null;
            }
        }
    }
public function adjacent ( $ direction , $ model , $ category_id = null , array $ with = [ ] , $ all = false ) { $ currentModel = $ model ; if ( $ category_id !== null ) { $ models = $ this -> with ( 'category' ) -> findWhere ( [ 'category_id' , $ category_id ] , [ 'id' , 'category_id' , 'slug' ] ) ; } else { $ models = $ this -> all ( [ 'id' , 'slug' ] ) ; } foreach ( $ models as $ key => $ model ) { if ( $ currentModel -> id == $ model -> id ) { $ adjacentKey = $ key + $ direction ; return isset ( $ models [ $ adjacentKey ] ) ? $ models [ $ adjacentKey ] : null ; } } }
Get prev model.

@param int   $direction
@param Model $model
@param int   $category_id
@param array $with
@param bool  $all

@return Model|null
Get prev model .