MyHomeCollection/app/Http/Controllers/PublicController.php

40 lines
1.1 KiB
PHP
Raw Normal View History

2020-07-24 13:11:21 +02:00
<?php
namespace App\Http\Controllers;
use App\Home;
use Artesaos\SEOTools\Traits\SEOTools as SEOToolsTrait;
use DateTime;
2020-07-24 13:11:21 +02:00
class PublicController extends Controller
{
use SEOToolsTrait;
2020-07-24 13:11:21 +02:00
public function show($slug)
{
$home = Home::where('slug', $slug)->firstOrFail();
$this->seo()
->setTitle($home->title)
->setDescription($home->excerpt())
2020-07-27 12:49:17 +02:00
->addImages(array_map(static function ($picture) {
return asset($picture);
}, $home->pictures));
$this->seo()
->opengraph()
->addProperty('article:published_time', $home->created_at->format(DateTime::ATOM))
->addProperty('article:author', 'Shikiryu');
2020-07-24 13:11:21 +02:00
return view('public.view', ['home' => $home]);
}
public function list()
{
$homes = Home::where('slug', '!=', null)->paginate(12);
$this->seo()
->setTitle('Liste des maisons rêvées')
->setDescription('La sélection');
return view('public.list', ['homes' => $homes]);
}
2020-07-24 13:11:21 +02:00
}