X

Create New Item

File Folder

X

Search Results

File "ManageCertificateController.php"

Full path: /home/orbitecv/orbite-school.orbit.et/app/Http/Controllers/WebAdmin/ManageCertificateController.php
File size: 1.96 KiB (2006 bytes)
MIME-type: text/x-php
Charset: utf-8

Download   Open   Edit   Advanced Edit   Back

<?php

namespace App\Http\Controllers\WebAdmin;

use App\Enum\MediaTypeEnum;
use App\Http\Controllers\Controller;
use App\Http\Requests\ManageCertificateRequest;
use App\Models\Frame;
use App\Models\ManageCertificate;
use App\Repositories\FrameRepository;
use App\Repositories\ManageCertificateRepository;
use Illuminate\Http\Request;

class ManageCertificateController extends Controller
{
    /**
     * Display a listing of the resource.
     */
    public function index()
    {
        $frames = FrameRepository::query()->get();
        $certificate = ManageCertificateRepository::query()->latest('id')->first();
        return view('certificateConfigaration.index', compact('certificate', 'frames'));
    }

    /**
     * Update the specified resource in storage.
     */
    public function update(ManageCertificateRequest $request)
    {
        $organization = app()->bound('currentOrganization') ? app('currentOrganization') : null;
        $certificate = ManageCertificateRepository::query()->latest('id')->first();

        if ($organization) {
            $request->merge(['organization_id' => $organization->id]);
            $certificate = ManageCertificateRepository::query()->where('organization_id', $organization->id)->latest('id')->first();
        }

        if ($request->hasFile('frame_id')) {
            FrameRepository::storeByRequest(
                $organization ? $organization->id : null,
                $request->file('frame_id'),
                'frame',
                MediaTypeEnum::IMAGE
            );

            return to_route('certificate.index')->withSuccess('Frame updated');
        }

        ManageCertificateRepository::updateByRequest($request, $certificate);

        return to_route('certificate.index')->withSuccess('Configaration updated');
    }

    public function delete($id)
    {
        $frame = Frame::findOrFail($id);
        $frame->delete();
        return to_route('certificate.index')->withSuccess('Frame deleted successfully');
    }
}