-
-
Notifications
You must be signed in to change notification settings - Fork 112
Expand file tree
/
Copy pathShowBlogController.php
More file actions
65 lines (52 loc) · 1.84 KB
/
Copy pathShowBlogController.php
File metadata and controls
65 lines (52 loc) · 1.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php
namespace App\Http\Controllers;
use App\Models\Article;
use App\Support\BlogFeed;
use Artesaos\SEOTools\Facades\SEOTools;
use Illuminate\Http\Response;
class ShowBlogController extends Controller
{
public function index()
{
$articles = Article::query()
->published()
->paginate(6);
return view('blog', [
'articles' => $articles,
]);
}
public function feed(BlogFeed $feed): Response
{
$articles = Article::query()
->published()
->with('author')
->limit(20)
->get();
return response($feed->toRss($articles), 200, [
'Content-Type' => 'application/rss+xml; charset=UTF-8',
]);
}
public function show(Article $article)
{
abort_unless($article->isPublished() || $article->isScheduled() || auth()->user()?->isAdmin(), 404);
// Set SEO metadata for the article
SEOTools::setTitle($article->title.' - Blog');
SEOTools::setDescription($article->excerpt ?: 'Read this article on the NativePHP blog.');
// Set OpenGraph metadata
SEOTools::opengraph()->setTitle($article->title);
SEOTools::opengraph()->setDescription($article->excerpt ?: 'Read this article on the NativePHP blog.');
SEOTools::opengraph()->setType('article');
if ($article->og_image) {
SEOTools::opengraph()->addImage($article->og_image);
}
// Set Twitter Card metadata
SEOTools::twitter()->setTitle($article->title);
SEOTools::twitter()->setDescription($article->excerpt ?: 'Read this article on the NativePHP blog.');
if ($article->og_image) {
SEOTools::twitter()->setImage($article->og_image);
}
return view('article', [
'article' => $article,
]);
}
}