You've already forked Atomcms-edit
Initial commit
This commit is contained in:
Executable
+24
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\Articles;
|
||||
|
||||
use App\Models\Articles\WebsiteArticle;
|
||||
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
|
||||
readonly class ArticleService
|
||||
{
|
||||
public function getArticles(bool $paginate = false, int $perPage = 8): array|Collection|LengthAwarePaginator
|
||||
{
|
||||
$query = WebsiteArticle::query()->with(['user' => function ($query) {
|
||||
$query->select('id', 'username', 'look');
|
||||
}])->orderByDesc('id');
|
||||
|
||||
return $paginate ? $query->paginate($perPage) : $query->get();
|
||||
}
|
||||
|
||||
public function fetchArticle(string $slug): WebsiteArticle
|
||||
{
|
||||
return WebsiteArticle::query()->where('slug', '=', $slug)->firstOrFail();
|
||||
}
|
||||
}
|
||||
Executable
+48
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\Articles;
|
||||
|
||||
use App\Models\Articles\WebsiteArticle;
|
||||
use App\Models\Articles\WebsiteArticleComment;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
readonly class CommentService
|
||||
{
|
||||
public function store(string $comment, WebsiteArticle $article): mixed
|
||||
{
|
||||
if ($article->userHasReachedArticleCommentLimit()) {
|
||||
return redirect()->back()->withErrors([
|
||||
'message' => __('You can only comment :amount times per article', ['amount' => setting('max_comment_per_article')]),
|
||||
]);
|
||||
}
|
||||
|
||||
if (! $article->can_comment) {
|
||||
return redirect()->back()->withErrors([
|
||||
'message' => __('This article has been locked from receiving comments'),
|
||||
]);
|
||||
}
|
||||
|
||||
return $article->comments()->create([
|
||||
'user_id' => Auth::id(),
|
||||
'comment' => $comment,
|
||||
]);
|
||||
}
|
||||
|
||||
public function destroy(WebsiteArticleComment $comment): bool|RedirectResponse|null
|
||||
{
|
||||
if (! $comment->canBeDeleted()) {
|
||||
return redirect()->back()->withErrors([
|
||||
'message' => __('You can only delete your own comments'),
|
||||
]);
|
||||
}
|
||||
|
||||
if (! $comment->delete()) {
|
||||
return redirect()->back()->withErrors([
|
||||
'message' => __('An error occurred while deleting the comment'),
|
||||
]);
|
||||
}
|
||||
|
||||
return $comment->delete();
|
||||
}
|
||||
}
|
||||
Executable
+36
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\Articles;
|
||||
|
||||
use App\Models\Articles\WebsiteArticle;
|
||||
use App\Models\Articles\WebsiteArticleReaction;
|
||||
use App\Models\User;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
readonly class ReactionService
|
||||
{
|
||||
public function toggleReaction(WebsiteArticle $article, User $user, Request $request): array
|
||||
{
|
||||
$reaction = $request->get('reaction');
|
||||
|
||||
if (! is_string($reaction) || ! in_array($reaction, config('habbo.reactions'))) {
|
||||
return ['success' => false];
|
||||
}
|
||||
|
||||
$existingReaction = WebsiteArticleReaction::getReaction($article->id, $user->id, $reaction);
|
||||
|
||||
if ($existingReaction instanceof WebsiteArticleReaction) {
|
||||
$existingReaction->update(['active' => ! $existingReaction->active]);
|
||||
} else {
|
||||
$article->reactions()->create([
|
||||
'reaction' => $reaction,
|
||||
]);
|
||||
}
|
||||
|
||||
return [
|
||||
'success' => true,
|
||||
'added' => $existingReaction->active ?? true,
|
||||
'username' => $user->username,
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user