Files
ai-stylegallery/app/Http/Controllers/HomeController.php

36 lines
1.1 KiB
PHP

<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\Setting;
use App\Models\Image;
use Inertia\Inertia;
use Illuminate\Support\Facades\Lang;
use Carbon\Carbon;
class HomeController extends Controller
{
public function index()
{
$locale = app()->getLocale();
$translations = array_merge(
Lang::get('api', [], $locale),
Lang::get('settings', [], $locale)
);
$galleryHeading = Setting::where('key', 'gallery_heading')->first()->value ?? 'Style Gallery';
$newImageTimespanMinutes = Setting::where('key', 'new_image_timespan_minutes')->first()->value ?? 60; // Default to 60 minutes
$images = Image::all()->map(function ($image) use ($newImageTimespanMinutes) {
$image->is_new = Carbon::parse($image->created_at)->diffInMinutes(Carbon::now()) <= $newImageTimespanMinutes;
$image->path = 'storage/' . $image->path;
return $image;
});
return Inertia::render('Home', [
'translations' => $translations,
'galleryHeading' => $galleryHeading,
'images' => $images,
]);
}
}