HEX
Server: Apache/2.4.41 (Ubuntu)
System: Linux ip-172-31-42-149 5.15.0-1084-aws #91~20.04.1-Ubuntu SMP Fri May 2 07:00:04 UTC 2025 aarch64
User: ubuntu (1000)
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: /var/www/vhost/disk-apps/agile-selling-wpb/app/Http/Controllers/MatchEventZonePricesController.php
<?php

namespace App\Http\Controllers;

use DataTables;
use App\Zone;
use App\MatchEvent;
use App\MatchEventZonePrice;
use Illuminate\Http\Request;

class MatchEventZonePricesController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index($event_id)
    {
        return view('matcheventzoneprices.list', compact('event_id'));
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create($event_id)
    {
        $event = MatchEvent::findOrFail($event_id);
        $zones = Zone::where([['is_saleable', true],['active', true]])->with('zone')->get();
        return view('matcheventzoneprices.create', compact("event", "zones", "event_id"));
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        if (!MatchEventZonePrice::where([['match_event_id', $request->match_event_id], ['zone_id', $request->zone_id]])->first()) {
            if (MatchEventZonePrice::create($request->all())) {
                return response(array("r" => true, "type" => "success", "title" => "", "m" => __('messages.created_successfully'), "data" => null));
            } else {
                return response(array("r" => false, "type" => "error", "title" => "Oops...", "m" => __('messages.error_creating'), "data" => null));
            }
        }else{
            return response(array("r" => false, "type" => "error", "title" => "Oops...", "m" => __('messages.already_exists_match_event_price'), "data" => null));
        }
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        return redirect()->back();
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
        $matchEventZonePrice = MatchEventZonePrice::findOrFail($id);
        $event = MatchEvent::findOrFail($matchEventZonePrice->match_event_id);
        $zones = Zone::where([['is_saleable', true],['active', true]])->get();
        return view('matcheventzoneprices.edit', compact('zones','matchEventZonePrice','event'));
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
        if (!MatchEventZonePrice::where([['id', '!=', $id], ['zone_id', $request->input('zone_id')], ['match_event_id', $request->input('match_event_id')]])->first()) {
            if (MatchEventZonePrice::where('id', $id)->update($request->all())) {
                return response(array("r" => true, "type" => "success", "title" => "", "m" => __('messages.updated_successfully'), "data" => null));
            } else {
                return response(array("r" => false, "type" => "error", "title" => "Oops...", "m" => __('messages.error_updating'), "data" => null));
            }
        }else{
            return response(array("r" => false, "type" => "error", "title" => "Oops...", "m" => __('messages.already_exists_match_event_price'), "data" => null));
        }
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        try {
            if (MatchEventZonePrice::where('id', $id)->delete()) {
                return response(array("r" => true, "type" => "success", "title" => "", "m" => __('messages.deleted_successfully'), "data" => null));
            } else {
                return response(array("r" => false, "type" => "error", "title" => "Oops...", "m" => __('messages.error_removing'), "data" => null));
            }
        } catch (\Illuminate\Database\QueryException $e) {
            return response(array("r" => false, "type" => "error", "title" => "Oops...", "m" => __('messages.delete_relation_data'), "data" => null));
        }
    }

    public function tableFilter($event_id)
    {
        $obj = MatchEventZonePrice::where('match_event_id', $event_id)
                                    ->select('id', 'zone_id', 'match_event_id', 'price', 'price_suscription')
                                    ->with('zone','match_event');

        return DataTables::of($obj)
            ->addColumn('actions', function ($obj) {
                return '
                <i class="fa fa-pencil iconMini " onClick="clickEdit(' . $obj->id . ')" data-id="' . $obj->id . '" data-toggle="tooltip" data-placement="bottom"  style="cursor:pointer;"></i>
                <i class="fa fa-trash iconMini " onClick="clickDelete(' . $obj->id . ', '. $obj->match_event_id .')" data-id="' . $obj->id . '" data-toggle="tooltip" data-placement="bottom"  style="cursor:pointer;"></i>
            ';
            })
            ->rawColumns(['actions'])
            ->make(true);
    }
}