Files

54 lines
1.7 KiB
PHP
Raw Permalink Normal View History

<?php
namespace App\Http\Controllers;
use App\Models\Education;
use App\Models\Experience;
use App\Models\Post;
use App\Models\Profile;
use App\Models\Project;
use Illuminate\View\View;
class HomeController extends Controller
{
public function index(): View
{
$profile = Profile::query()->first();
$timeline = Experience::query()->get()->map(fn (Experience $item) => (object) [
'type' => 'work',
'title' => $item->role,
'subtitle' => $item->company,
'start_date' => $item->start_date,
'end_date' => $item->end_date,
'is_current' => $item->is_current,
'description' => $item->description,
])->concat(Education::query()->get()->map(fn (Education $item) => (object) [
'type' => 'education',
'title' => $item->degree
? $item->degree . ($item->field_of_study ? " in {$item->field_of_study}" : '')
: $item->institution,
'subtitle' => $item->institution,
'start_date' => $item->start_date,
'end_date' => $item->end_date,
'is_current' => false,
'description' => $item->description,
]))->sortByDesc(fn (object $item) => $item->start_date)->values();
$projects = Project::query()
->orderByDesc('is_featured')
->orderBy('sort_order')
->orderByDesc('created_at')
->limit(4)
->get();
$posts = Post::query()
->published()
->orderByDesc('published_at')
->limit(3)
->get();
return view('home', compact('profile', 'timeline', 'projects', 'posts'));
}
}