@php use Illuminate\Support\Facades\File; use Carbon\Carbon; $folderPath = public_path('uploads/current-affairs'); $files = File::glob($folderPath . '/*.pdf'); $data = []; $errorMessage = null; try { $pattern = '/(\d{4}-\d{2}-\d{2}(?:_\d{4}-\d{2}-\d{2})*)/'; foreach ($files as $file) { $filename = pathinfo($file, PATHINFO_FILENAME); if (preg_match($pattern, $filename, $matches)) { $dateRange = $matches[1]; $dates = array_map(function ($date) { return Carbon::createFromFormat('Y-m-d', $date)->format('d M Y'); }, explode('_', $dateRange)); $dateRangeStr = implode(' - ', $dates); $displayName = 'Daily Current Affairs Synopsis'; } else { $creationDate = Carbon::createFromTimestamp(filectime($file))->format('d M Y'); $dateRangeStr = $creationDate; $displayName = $filename; } $data[] = [ 'date_range' => $dateRangeStr, 'display_name' => $displayName, 'url' => asset(rawurlencode('/uploads/current-affairs/' . basename($file))), 'modified_at' => filemtime($file), ]; } usort($data, function ($a, $b) { return $b['modified_at'] - $a['modified_at']; }); $perPage = 10; $currentPage = request()->get('page', 1); $paginatedData = array_slice($data, ($currentPage - 1) * $perPage, $perPage); $collection = collect($paginatedData); $paginator = new \Illuminate\Pagination\LengthAwarePaginator($collection, count($data), $perPage, $currentPage, [ 'path' => request()->url(), ]); } catch (\Exception $e) { $errorMessage = $e->getMessage(); } @endphp @extends('frontend.mainlayout') @section('title', 'Current Affairs - RERF Group of Institutions') @section('meta') @endsection @section('banner')

Current Affairs

Your Daily Source for Current Affairs and Important Updates

@endsection @section('main')
@foreach ($paginator as $item) @endforeach
Sl No Topic Date Action
{{ $loop->iteration + ($paginator->currentPage() - 1) * $paginator->perPage() }}

{{ $item['display_name'] }}

{{ $item['date_range'] }}

View/Download
{{ $paginator->links() }}
@endsection