HEX
Server: LiteSpeed
System: Linux php-prod-3.spaceapp.ru 5.15.0-151-generic #161-Ubuntu SMP Tue Jul 22 14:25:40 UTC 2025 x86_64
User: sarli3128 (1010)
PHP: 7.4.33
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: //home/marketing.cfbon.ru/public_html/app/Http/Controllers/Promotions/PromotionsController.php
<?php

namespace App\Http\Controllers\Promotions;

use App\Enums\PromotionType;
use App\Http\Controllers\Controller;
use App\Http\Requests\Promotion\PromotionRequest;
use App\Models\Promotion;
use Illuminate\View\View;

class PromotionsController extends Controller
{
    /**
     * Display a listing of the resource.
     */
    public function index() : View
    {
        return view('promotions.index', [
            'sitePromotion' => [
                'type' => PromotionType::SITE,
                'promotions' => Promotion::where('promotion_type', PromotionType::SITE->value)->get(),
            ],
            'mobilePromotion' => [
                'type' => PromotionType::MOBILE,
                'promotions' => Promotion::where('promotion_type', PromotionType::MOBILE->value)->get(),
            ],
        ]);
    }

    /**
     * Show the form for creating a new resource.
     */
    public function create() : View
    {
        return view('promotions.create', [
            'promotionType' => collect(PromotionType::cases())
                ->mapWithKeys(fn($type) => [$type->value => $type->label()]),
            'selectType' => request()->query('type', PromotionType::SITE->value),
        ]);
    }

    /**
     * Store a newly created resource in storage.
     */
    public function store(PromotionRequest $request)
    {
        Promotion::create([
            'name' => $request->input('name'),
            'title' => $request->input('title'),
            'description' => $request->input('description'),
            'is_active' => $request->input('is_active'),
            'img' => $request->file('img'),
            'promotion_type' => $request->input('promotion_type'),
        ]);
        return redirect()->route('promotions.index')->with('success', 'Акция добавлена');
    }

    /**
     * Show the form for editing the specified resource.
     */
    public function edit(string $id)
    {
        $promotion = Promotion::findOrFail($id);
        return view('promotions.edit', [
            'promotion' => $promotion,
            'promotionType' => collect(PromotionType::cases())
                ->mapWithKeys(fn($type) => [$type->value => $type->label()]),
        ]);
    }

    /**
     * Update the specified resource in storage.
     */
    public function update(PromotionRequest $request, string $id)
    {
        $promotion = Promotion::findOrFail($id);

        $promotion->update($request->validated());

        return redirect()->back()->with('success', 'Изменения успешно применены');
    }

    /**
     * Remove the specified resource from storage.
     */
    public function destroy(string $id)
    {
        $promotion = Promotion::findOrFail($id);
        $promotion->delete();

        return redirect()->route('promotions.index')->with('success', 'Акция удалена');
    }
}