HEX
Server: Apache/2.4.46 (Ubuntu)
System: Linux localhost 5.11.0-49-generic #55-Ubuntu SMP Wed Jan 12 17:36:34 UTC 2022 x86_64
User: root (0)
PHP: 7.4.16
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/html/sarvodayahospital/app/Http/Controllers/AwardController.php
<?php

namespace App\Http\Controllers;

use App\Models\Award;
use App\Models\CMSPage;
use Illuminate\Support\Facades\DB;
use Illuminate\Http\Request;

class AwardController extends Controller
{
    public function index(Request $request)
    {
        $sort_by = $request->filled('sortby') ? $request->get('sortby') : 'id';
        $by_year = $request->filled('year') ? (int) $request->get('year') : 0;
        $by_month = $request->filled('month') ? (int) $request->get('month') : null;
        $seo = [];

        $query = Award::query();

        $query->when(
            $by_year > 0,
            function ($q) use ($by_year) {
                return $q->whereYear('Date', $by_year);
            }
        );

        if ($by_year == 0) {
            $query->when(
                $by_month > 0,
                function ($q) use ($by_month) {
                    return $q->whereMonth('Date', $by_month)
                        ->whereYear('Date', date("Y"));
                }
            );
        } else {
            $query->when(
                $by_month > 0,
                function ($q) use ($by_month) {
                    return $q->whereMonth('Date', $by_month);
                }
            );
        }

        $awards = $query->select('id', 'AwardName', 'Slug', 'Date')
            ->orderby('Date', 'DESC')
            ->paginate(20);

        $years = Award::query()
            ->select(DB::raw('YEAR(Date) as publicationYear'))
            ->groupBy('publicationYear')
            ->orderBy('publicationYear', 'DESC')
            ->get();

        $cmsPage = CMSPage::query()
            ->where('Slug', request()->path())
            ->firstOrFail();

        if ($cmsPage) {
            $seo = $cmsPage->seoComponent()->first();
        }

        return view('pages.award', compact('awards', 'years', 'seo'));
    }

    public function show($slug)
    {
        $seo = [];

        $award = Award::query()
            ->where('Slug', $slug)
            ->firstOrFail();

        if ($award) {
            $seo = $award->seoComponent()->first();
        }

        $awards = $awards = Award::query()
            ->where('Slug', '!=', $slug)
            ->select('id', 'AwardName', 'Slug', 'Date')
            ->take(6)
            ->get();

        return view('pages.single-award', compact('award', 'awards', 'seo'));
    }
}