private function getSizessAsArray()
 {
     $sizes = ProductSize::all();
     $arr = ['no size selected'];
     foreach ($sizes as $size) {
         $arr[$size->id] = $size->size . ' of product ' . $size->product->name;
     }
     return $arr;
 }
Example #2
0
 private function isSizeExist($size, $id)
 {
     if (!$size) {
         $sizes = ProductSize::all();
         if (!$sizes->count()) {
             return ['error' => true, 'data' => ['message' => 'No sizes exist.', 'links' => [['url' => 'panel/products/sizes', 'text' => 'Go to table ']]]];
         }
         $firstSize = $sizes[0];
         $middleSize = $sizes[intval((count($sizes) - 1) / 2)];
         $lastSize = $sizes[count($sizes) - 1];
         $firstDiff = abs($firstSize->id - $id);
         $middleDiff = abs($middleSize->id - $id);
         $lastDiff = abs($lastSize->id - $id);
         if ($firstDiff < $middleDiff && $firstDiff < $lastDiff) {
             $sizeLF = $firstSize;
         } else {
             if ($firstDiff > $middleDiff && $middleDiff < $lastDiff) {
                 $sizeLF = $middleSize;
             } else {
                 if ($firstDiff > $lastDiff && $middleDiff > $lastDiff) {
                     $sizeLF = $lastSize;
                 } else {
                     $sizeLF = $firstSize;
                 }
             }
         }
         $links = [['url' => 'panel/products/sizes', 'text' => 'Go to table'], ['url' => 'panel/products/sizes/' . $sizeLF->id . '/edit', 'text' => 'May be you looking for "' . $sizeLF->size . '" size.']];
         if ($firstDiff != $middleDiff && $firstDiff != $lastDiff && $middleDiff != $lastDiff) {
             $links[2] = ['url' => null, 'text' => 'Or you want other sizes?'];
             $links[3] = ['url' => 'panel/products/sizes/' . $firstSize->id . '/edit', 'text' => '1. "' . $firstSize->size . '" size.'];
             $links[4] = ['url' => 'panel/products/sizes/' . $middleSize->id . '/edit', 'text' => '2. "' . $middleSize->size . '" size.'];
             $links[5] = ['url' => 'panel/products/sizes/' . $lastSize->id . '/edit', 'text' => '2. "' . $lastSize->size . '" size.'];
         }
         return ['error' => true, 'data' => ['message' => 'Size with this id does not exist.', 'links' => $links]];
     }
     return ['error' => false];
 }