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/comfama.sports-crowd.com/app/Http/Controllers/BrandsController.php
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use App\Brand;
use Datatables;
use DB;

class BrandsController extends Controller
{
    public function index($storeType = 'main')
    {
        $brands = Brand::orderBy('name', 'ASC')->get();
        return view('brands.brands')->with('brands', $brands)->with('storeType', $storeType);
    }

    public function indexEdit($id)
    {
        $brand = Brand::find($id);
        return view('brands.editBrands')->with('brand', $brand);
    }

    public function create(Request $request)
    {
        $r = Brand::where('name', $request["name"])->first();
        if ($r) {
            return array('r' => false, 'm' => trans('messages.controller_brand_tag1'), 'd' => $r);
        }

        $brand              = new Brand();
        $brand->name        = $request["name"];
        $brand->store_type  = $request["store_type"];
        $brand->save();

        $logObj = $brand;
        if (Auth::user()) {
            $this->registerLog(Auth::user()->id, 'Creó marca', json_encode($logObj), "Create", 5);
        }
        return array('r' => true, 'm' => trans('messages.controller_brand_tag2'), 'd' => $brand);
    }

    public function update(Request $request)
    {
        $id = $request["id"];
        $brand = Brand::find($id);
        $logObj = $brand;
        $r = Brand::where('name', $request["name"])->first();
        if ($r) {
            if ($brand->name != $request["name"]) {
                return array('r' => false, 'm' => trans('messages.controller_brand_tag1'));
            }
        }
        $brand->name = $request["name"];
        $brand->update();

        $this->registerLog(Auth::user()->id, 'Actualizó marca ', json_encode($logObj), "Update", 5);
        return array('r' => true, 'm' => trans('messages.controller_brand_tag3'));
    }


    public function activate(Request $request)
    {
        $id = $request['id'];
        $state =  $request['state'];
        $brand = Brand::find($id);
        $logObj = $brand;
        $brand->active = $state;
        $brand->update();

        $this->registerLog(
            Auth::user()->id,
            'Actualizó marca',
            json_encode($logObj),
            "Update",
            5
        );
        return array('r' => true);
    }

    public function delete(Request $request)
    {
        $id = $request['id'];
        $brand = Brand::find($id);
        $logObj = $brand;
        $brand->delete();
        $this->registerLog(Auth::user()->id, 'Eliminó marca', json_encode($logObj), "Delete", 5);
        return array('r' => true);
    }

    public function tableFilter($storeType = 'main')
    {
        $obj = $obj = DB::table('brands')
            ->select('brands.id', 'brands.name', 'brands.active')
            ->whereNull('brands.deleted_at')
            ->where('brands.store_type', $storeType)->get();

        return Datatables::of($obj)
            ->addColumn('actions', function ($obj) {
                return '<i class="fa fa-pencil iconMini" onClick="clickEditBrand(' . $obj->id . ')" data-id="' . $obj->id . '"  title="Editar"></i>
                <i class="fa fa-trash iconMini" onClick="clickDeleteBrand(' . $obj->id . ')" data-id="' . $obj->id . '"  title="Eliminar"></i>';
            })
            ->editColumn('active', function ($obj) {
                if ($obj->active == 0) {
                    return '<div class="switch"><label><div class="checkbox checbox-switch switch-success"> <label> No <input type="checkbox" onChange="chkBrand(' . $obj->id . ')" data-id="' . $obj->id . '" id="Checkactive' . $obj->id . '" name="Checkactivo" /> <span></span>Si </label></div> </label> </div>';
                } else {
                    return '<div class="switch"><label> <div class="checkbox checbox-switch switch-success"> <label>   No <input type="checkbox" onChange="chkBrand(' . $obj->id . ')" data-id="' . $obj->id . '" id="Checkactive' . $obj->id . '" name="Checkactivo" checked="" />
                        <span></span> Si </label> </div>  </label> </div>';
                }
            })
            ->rawColumns(['active', 'actions'])
            ->make(true);
    }
}