HEX
Server: nginx/1.28.1
System: Linux 10-41-63-61 6.8.0-31-generic #31-Ubuntu SMP PREEMPT_DYNAMIC Sat Apr 20 00:40:06 UTC 2024 x86_64
User: www (1001)
PHP: 7.4.33
Disabled: passthru,exec,system,putenv,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,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_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv
Upload Files
File: /www/wwwroot//www.shooperm.com/Modules/Product/Http/Controllers/AttributeController.php
<?php

namespace Modules\Product\Http\Controllers;

use Illuminate\Contracts\Support\Renderable;
use Illuminate\Http\Request;
use Illuminate\Routing\Controller;
use Modules\Product\Services\AttributeService;
use Modules\Product\Http\Requests\AttributeFormRequest;
use Brian2694\Toastr\Facades\Toastr;
use Modules\UserActivityLog\Traits\LogActivity;

class AttributeController extends Controller
{
    protected $attributeService;

    public function __construct(AttributeService $attributeService)
    {
        $this->middleware('maintenance_mode');
        $this->attributeService = $attributeService;
    }

    public function index()
    {
        $data['attributes'] = $this->attributeService->getAll();
        return view('product::attributes.index', $data);
    }

    public function get_list()
    {
        $data['attributes'] = $this->attributeService->getAll();
        return view('product::attributes.attributes_list', $data);
    }

    public function store(AttributeFormRequest $request)
    {
        try {
            $this->attributeService->save($request->except("_token"));
            LogActivity::successLog('Attribute Added.');

            if (isset($request->form_type)) {
                if ($request->form_type == 'modal_form') {
                    $attributes = $this->attributeService->getActiveAll();
                    return view('product::products.components._attribute_list_select', compact('attributes'));
                } else {
                    return response()->json(["message" => "Attribute Added Successfully"], 200);
                }
            } else {
                return response()->json(["message" => "Attribute Added Successfully"], 200);
            }
        } catch (\Exception $e) {
            LogActivity::errorLog($e->getMessage());
            return response()->json(["message" => "Something Went Wrong", "error" => $e->getMessage()], 503);
        }
    }

    public function show(Request $request)
    {

        try {
            $atribute = $this->attributeService->findById($request->id);

            $values = [];
            foreach ($atribute->values as $key => $value) {
                array_push($values, $value->value);
            }

            return view('product::attributes.show', [
                "atribute" => $atribute,
                'values' => $values
            ]);
        } catch (\Exception $e) {
            LogActivity::errorLog($e->getMessage());
            return response()->json(["message" => "Something Went Wrong", "error" => $e->getMessage()], 503);
        }
    }

    public function edit($id)
    {
        try {
            $attribute = $this->attributeService->findById($id);
            return view('product::attributes.edit_attribute',compact('attribute'));
        } catch (\Exception $e) {
            LogActivity::errorLog($e->getMessage());
            return response()->json(["message" => "Something Went Wrong", "error" => $e->getMessage()], 503);
        }
    }

    public function update(AttributeFormRequest $request, $id)
    {
        try {
            $this->attributeService->update($request->except("_token"), $id);
            LogActivity::successLog('Attribute Updated.');
            return response()->json([
                "message" => "Attribute Updated Successfully",
                "createForm" => (string)view('product::attributes.create_attribute')
            ], 200);
        } catch (\Exception $e) {
            LogActivity::errorLog($e->getMessage());
            return response()->json(["message" => "Something Went Wrong", "error" => $e->getMessage()], 503);
        }
    }

    public function destroy($id)
    {
        try {
            if($id == 1){
                Toastr::warning(__('product.color_attribute_is_not_deletable'));
                return back();
            }
            $result = $this->attributeService->deleteById($id);
            if ($result == "not_possible") {
                Toastr::warning(__('product.related_data_exist_in_multiple_directory'));
                return back();
            } else {
                LogActivity::successLog('Attribute Deleted.');
                Toastr::success(__('common.deleted_successfully'), __('common.success'));
                return redirect()->route('product.attribute.index');
            }
        } catch (\Exception $e) {
            LogActivity::errorLog($e->getMessage());
            Toastr::error(__('common.Something Went Wrong'));
            return back();
        }
    }

    public function attribute_values(Request $request)
    {

        try {
            $attribute = $request->id;
            return view('product::products.selected_attributes', compact('attribute'));
        } catch (\Exception $e) {
            LogActivity::errorLog($e->getMessage());
            return response()->json(["message" => "Something Went Wrong", "error" => $e->getMessage()], 503);
        }
    }
}