app/Models/Category.php
/**
     * Retool positions if the requested has been already occupied.
     * 
     * @param int $position
     * @return void
     */
Retool positions if the requested has been already occupied.

@param int $position
@return void
Retool positions if the requested has been already occupied . @param int $position @return void
public function retoolPositions($position)
    {
        $id = $this->id;
        $occupied = self::where('position', $position)->first();
        if($occupied != null && $occupied->id != $id){
            $items = self::where('position', '>=', $position)->get();
            foreach($items as $item){
                $newPosition = $item->position + 1;
                $item->update([
                    'position' => $newPosition
                ]);
            }
        }
    }
public function retoolPositions ( $ position ) { $ id = $ this -> id ; $ occupied = self :: where ( 'position' , $ position ) -> first ( ) ; if ( $ occupied != null && $ occupied -> id != $ id ) { $ items = self :: where ( 'position' , '>=' , $ position ) -> get ( ) ; foreach ( $ items as $ item ) { $ newPosition = $ item -> position + 1 ; $ item -> update ( [ 'position' => $ newPosition ] ) ; } } }
Retool positions if the requested has been already occupied.
Retool positions if the requested has been already occupied .