Файловый менеджер - Редактировать - /home/clickysoft/public_html/calvary-p2.clickysoft.net/app/Console/Commands/CloneHotLunch.php
Назад
<?php namespace App\Console\Commands; use App\Models\HotLunch; use Exception; use Illuminate\Console\Command; use Illuminate\Support\Facades\DB; class CloneHotLunch extends Command { /** * The name and signature of the console command. * * @var string */ protected $signature = 'app:clone-hot-lunch'; /** * The console command description. * * @var string */ protected $description = 'Command to clone Hot Lunch'; /** * Execute the console command. */ public function handle() { $hot_lunch = HotLunch::find(2); if (!$hot_lunch) { $this->info('Lunch not found!'); } DB::beginTransaction(); try { $hl_clone = $hot_lunch->replicate(); $hl_clone->title = $hot_lunch->title . ' Clone'; $hl_clone->lunch_half = 'second_half'; $hl_clone->reg_starts = now()->startOfMonth(); $hl_clone->reg_ends = now()->endOfMonth(); $hl_clone->status = 0; $hl_clone->save(); foreach ($hot_lunch->hotLunchMenu as $menu) { $menu_clone = $menu->replicate(); $menu_clone->hot_lunch_id = $hl_clone->id; $menu_clone->save(); foreach ($menu->items as $item) { $item_clone = $item->replicate(); $item_clone->hot_lunch_menu = $menu_clone->id; $item_clone->save(); } foreach ($menu->grades as $grade) { $grade_clone = $grade->replicate(); $grade_clone->hot_lunch_menu_id = $menu_clone->id; $grade_clone->save(); } } DB::commit(); $this->info('Hot lunch cloned successfully!'); } catch (Exception $e) { DB::rollBack(); $this->info("Unable to clone hot lunch. " . $e->getMessage()); } } }
| ver. 1.4 |
Github
|
.
| PHP 8.1.29 | Генерация страницы: 0 |
proxy
|
phpinfo
|
Настройка