Skip to content

Commit d7e88a9

Browse files
committed
✨ ajout du tag sponsor sur les articles
1 parent 5982458 commit d7e88a9

File tree

8 files changed

+43
-20
lines changed

8 files changed

+43
-20
lines changed

app/Http/Controllers/ArticlesController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public function show(Article $article)
2525

2626
views($article)->record();
2727

28-
$article = Cache::remember('post-' . $article->id, now()->addDays(2), fn () => $article);
28+
$article = Cache::remember('post-' . $article->id, now()->addHour(), fn () => $article);
2929

3030
abort_unless(
3131
$article->isPublished() || ($user && $user->hasAnyRole(['admin', 'moderator'])),

app/Http/Controllers/HomeController.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ public function index()
1515
{
1616
$latestArticles = Cache::remember('latestArticles', now()->addHour(), function () {
1717
return Article::with('tags')
18+
->orderByDesc('sponsored_at')
19+
->orderByDesc('submitted_at')
1820
->orderByViews()
1921
->published()
2022
->trending()

app/Http/Livewire/Articles/Browse.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ public function validSort($sort): bool
2929
public function render()
3030
{
3131
$articles = Article::with('tags')->published()
32-
->notPinned();
32+
->notPinned()
33+
->orderByDesc('sponsored_at')
34+
->orderByDesc('submitted_at');
3335

3436
$tags = Tag::whereHas('articles', function ($query) {
3537
$query->published();

app/Models/Article.php

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ class Article extends Model implements ReactableInterface, HasMedia, Viewable
4242
'cover_image',
4343
'show_toc',
4444
'is_pinned',
45-
'is_sponsored',
4645
'user_id',
4746
'tweet_id',
4847
'submitted_at',
@@ -65,7 +64,6 @@ class Article extends Model implements ReactableInterface, HasMedia, Viewable
6564
'sponsored_at' => 'datetime',
6665
'show_toc' => 'boolean',
6766
'is_pinned' => 'boolean',
68-
'is_sponsored' => 'boolean',
6967
];
7068

7169
/**
@@ -171,6 +169,16 @@ public function isNotApproved(): bool
171169
return $this->approved_at === null;
172170
}
173171

172+
public function isSponsored(): bool
173+
{
174+
return ! $this->isNotSponsored();
175+
}
176+
177+
public function isNotSponsored(): bool
178+
{
179+
return $this->sponsored_at === null;
180+
}
181+
174182
public function isDeclined(): bool
175183
{
176184
return ! $this->isNotDeclined();
@@ -196,11 +204,6 @@ public function isPinned(): bool
196204
return (bool) $this->is_pinned;
197205
}
198206

199-
public function isSponsored(): bool
200-
{
201-
return (bool) $this->is_sponsored;
202-
}
203-
204207
public function isNotShared(): bool
205208
{
206209
return $this->shared_at === null;
@@ -283,6 +286,11 @@ public function scopeDeclined(Builder $query): Builder
283286
return $query->whereNotNull('declined_at');
284287
}
285288

289+
public function scopeSponsored(Builder $query): Builder
290+
{
291+
return $query->whereNotNull('sponsored_at');
292+
}
293+
286294
public function scopeNotDeclined(Builder $query): Builder
287295
{
288296
return $query->whereNull('declined_at');

public/css/app.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/mix-manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
22
"/js/app.js": "/js/app.js?id=9abd09e80a5426001802",
3-
"/css/app.css": "/css/app.css?id=ad2924a5bdd26f7adc2f"
3+
"/css/app.css": "/css/app.css?id=1b6e5ebdedf4aff61229"
44
}

resources/views/components/articles/overview.blade.php

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,17 @@
77
</div>
88
</a>
99
<div class="sm:col-span-2">
10-
@if ($article->tags->isNotEmpty())
11-
<div class="flex items-center space-x-2">
12-
@foreach ($article->tags as $tag)
13-
<x-tag :tag="$tag" />
14-
@endforeach
15-
</div>
16-
@endif
10+
<div class="flex items-center space-x-3">
11+
@if ($article->tags->isNotEmpty())
12+
<div class="flex items-center space-x-2">
13+
@foreach ($article->tags as $tag)
14+
<x-tag :tag="$tag" />
15+
@endforeach
16+
</div>
17+
@endif
18+
19+
<x-articles.sponsored :isSponsored="$article->isSponsored()" />
20+
</div>
1721
<div class="mt-2">
1822
<a href="{{ route('articles.show', $article) }}" class="group">
1923
<h4 class="text-lg leading-6 font-semibold font-sans text-skin-inverted group-hover:text-skin-primary">{{ $article->title }}</h4>
@@ -23,14 +27,14 @@
2327
</p>
2428
<div class="mt-3 flex items-center font-sans">
2529
<div class="flex-shrink-0">
26-
<a href="/user/{{ $article->author->username }}">
30+
<a href="{{ route('profile', $article->author->username) }}">
2731
<span class="sr-only">{{ $article->author->name }}</span>
2832
<img class="h-10 w-10 rounded-full" src="{{ $article->author->profile_photo_url }}" alt="{{ $article->author->name }}">
2933
</a>
3034
</div>
3135
<div class="ml-3">
3236
<p class="text-sm font-medium text-skin-inverted">
33-
<a href="/user/{{ $article->author->username }}" class="hover:underline">
37+
<a href="{{ route('profile', $article->author->username) }}" class="hover:underline">
3438
{{ $article->author->name }}
3539
</a>
3640
</p>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
@props(['isSponsored'])
2+
3+
@if($isSponsored)
4+
<span class="inline-flex items-center leading-none px-2.5 py-2 text-sm font-medium text-white rounded-full bg-gradient-to-r from-[#413626] to-[#7E5D36] font-sans">
5+
Sponsorisé
6+
</span>
7+
@endif

0 commit comments

Comments
 (0)