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/FrontendCMS/Http/Controllers/FeatureController.php
<?php

namespace Modules\FrontendCMS\Http\Controllers;

use Brian2694\Toastr\Facades\Toastr;
use Exception;
use Illuminate\Contracts\Support\Renderable;
use Illuminate\Http\Request;
use Illuminate\Routing\Controller;
use Modules\FrontendCMS\Http\Requests\CreateFeatureRequest;
use Modules\FrontendCMS\Http\Requests\UpdateFeatureRequest;
use \Modules\FrontendCMS\Services\FeatureService;
use Modules\UserActivityLog\Traits\LogActivity;

class FeatureController extends Controller
{
    protected $featureService;

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

    public function index()
    {
        try {
            $data['FeatureList'] = $this->featureService->getAll();
        } catch (Exception $e) {
            LogActivity::errorLog($e->getMessage());
            Toastr::error(__('common.operation_failed'));
            return back();
        }
        return view('frontendcms::feature.index', $data);
    }

    public function list()
    {
        $FeatureList = $this->featureService->getAll();
        return view('frontendcms::feature.componant.list', compact('FeatureList'));
    }

    public function store(CreateFeatureRequest $request)
    {
        try {
            $this->featureService->save($request->only('title', 'slug', 'icon', 'status'));

            LogActivity::successLog('Feature added.');

            return $this->loadTableData();
        } catch (Exception $e) {
            LogActivity::errorLog($e->getMessage());
            return response()->json([
                'status' => false,
                'error' => $e
            ]);
        }

    }

    public function show($id)
    {
        try {
            $feature = $this->featureService->showById($id);
            return response()->json([
                'status' => true,
                'TableData' =>  (string)view('frontendcms::feature.components.list', compact('FeatureList'))
            ]);
        } catch (Exception $e) {
            LogActivity::errorLog($e->getMessage());
            return response()->json([
                'status' => false,
                'error' => $e
            ]);
        }
        return view('frontendcms::show');
    }

    public function edit($id){

        $feature = $this->featureService->showById($id);
        return view('frontendcms::feature.components.edit',compact('feature'));
    }

    public function update(UpdateFeatureRequest $request)
    {
        try {
            $result = $this->featureService->update($request->only('title', 'slug', 'icon', 'status'), $request->id);
            LogActivity::successLog('Feature Updated.');
        } catch (Exception $e) {
            LogActivity::errorLog($e->getMessage());
            return response()->json([
                'status' => false,
                'error' => $e
            ]);
        }
        return  $this->loadTableData();
    }

    public function delete(Request $request)
    {
        try {
            $this->featureService->deleteById($request['id']);
            LogActivity::successLog('Feature Deleted.');
        } catch (Exception $e) {
            LogActivity::errorLog($e->getMessage());
            return response()->json([
                'status' => false,
                'error' => $e,
            ]);
        }

        return  $this->loadTableData();
    }

    private function loadTableData()
    {
        try {
            $FeatureList = $this->featureService->getAll();
            return response()->json([
                'status' => true,
                'TableData' =>  (string)view('frontendcms::feature.components.list', compact('FeatureList')),
                'createForm' =>  (string)view('frontendcms::feature.components.create')
            ]);
        } catch (\Exception $e) {
            LogActivity::errorLog($e->getMessage());
            return response()->json([
                'status' => false,
                'error' => $e
            ]);
        }
    }
}