Update Store Timeslot Options

3 years ago

godkinmo

Code

// η‡Ÿζ₯­ζ™‚ι–“: 上午 12:00 至 ζ™šδΈŠ 21:30

\App\Store::find(2)
  ->update([
  	'timeslot_options' => collect(range(12, 21))
      ->map(function ($hour) {
        return [
          [
            'from' => $hour . ":00",
            'to' => $hour . ":15",
            'max_count' => 5,
          ],
          [
            'from' => $hour . ":15",
            'to' => $hour . ":30",
            'max_count' => 5,
          ],
          [
            'from' => $hour . ":30",
            'to' => $hour . ":45",
            'max_count' => 5,
          ],
          [
            'from' => $hour . ":45",
            'to' => ($hour + 1) . ":00",
            'max_count' => 5,
          ],
        ];

      })->flatten(1)->slice(0, -2)->toArray()
  ])

Output

=> true
Video course: PHP Package Development