Skip to content
This repository was archived by the owner on Apr 4, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions app/Http/Controllers/ArticleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class ArticleController extends Controller
public function index()
{
$articles = Article::where([
'isPublished' => true,
'is_published' => true,
// 'isApproved' => true
])->with(['tags', 'user', 'reactions'])
->withCount('comments')->latest()->withScopes($this->scopes());
Expand Down Expand Up @@ -107,7 +107,7 @@ public function update(UpdateArticleRequest $request, Article $article)
{
$this->authorize('update', $article);

$article->update($request->only('title', 'slug', 'thumbnail', 'body', 'isPublished'));
$article->update($request->only('title', 'slug', 'thumbnail', 'body', 'is_published'));

if ($request->tags) {
$tags = collect($request->tags)->pluck('id');
Expand Down Expand Up @@ -151,8 +151,8 @@ public function destroy(Article $article)

public function myArticles(Request $request)
{
$published_count = auth()->user()->articles()->where('isPublished', true)->count();
$draft_count = auth()->user()->articles()->where('isPublished', false)->count();
$published_count = auth()->user()->articles()->where('is_published', true)->count();
$draft_count = auth()->user()->articles()->where('is_published', false)->count();
$my_articles_ids = auth()->user()->articles()->pluck('id');


Expand All @@ -165,11 +165,18 @@ public function myArticles(Request $request)
'type' => 'BOOKMARK',
])->whereIn('ReactionAble_id', $my_articles_ids)->count();

$reactions_count = Reaction::where([
'ReactionAble_type' => Article::getModel()->getMorphClass(),
])
->whereIn('type', ['UP_VOTE', 'DOWN_VOTE'])
->whereIn('ReactionAble_id', $my_articles_ids)->count();

$articles = auth()
->user()
->articles()
->where($request->only('isPublished'))
->latest()
->withCount('comments')
->paginate();

return AuthArticleList::collection($articles)->additional([
Expand All @@ -179,6 +186,7 @@ public function myArticles(Request $request)
'draft' => $draft_count,
'comments' => $comments_count,
'bookmarks' => $bookmark_count,
'reactions' => $reactions_count,
],
],
]);
Expand Down
11 changes: 6 additions & 5 deletions app/Http/Resources/Article/ArticleList.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,16 @@ public function toArray($request)
'id' => $this->id,
'title' => $this->title,
'slug' => $this->slug,
'url' => env('CLIENT_BASE_URL') . '/@' . $this->user->username . '/' . $this->slug,
'url' => config('app.client_url') . '/@' . $this->user->username . '/' . $this->slug,
'votes' => new VoteSummeryCollection($this->reactions),
'bookmarked_users' => new BookmarkCollection($this->reactions),
'comments_count' => $this->comments_count,
'thumbnail' => $this->thumbnail,
'bookmarked_users' => new BookmarkCollection($this->reactions),

'thumbnail' => json_decode($this->thumbnail),
'tags' => TagResource::collection($this->tags),
'body' => [
'html' => $md->toHTML(),
'markdown' => $this->body ?: '',
// 'html' => $md->toHTML(),
// 'markdown' => $this->body ?: '',
'plainText' => $md->toPlainText(),
'excerpt' => $this->getWordsFromStr(60, $md->toPlainText()),
],
Expand Down
8 changes: 6 additions & 2 deletions app/Http/Resources/Article/AuthArticleList.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,22 @@

namespace App\Http\Resources\Article;

use App\Http\Resources\Vote\VoteSummeryCollection;
use Illuminate\Http\Resources\Json\JsonResource;

class AuthArticleList extends JsonResource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request $request
* @param \Illuminate\Http\Request $request
* @return array|\Illuminate\Contracts\Support\Arrayable|\JsonSerializable
*/
public function toArray($request)
{
return parent::toArray($request);
return array_merge(parent::toArray($request), [
'votes' => new VoteSummeryCollection($this->reactions),
'comments_count' => $this->comments_count,
]);
}
}
4 changes: 2 additions & 2 deletions database/migrations/4_create_articles_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ public function up()
$table->string('seriesName')->nullable();
$table->text('body')->nullable();
$table->string('excerpt')->nullable();
$table->boolean('isPublished')->default(false);
$table->boolean('isApproved')->default(false);
$table->boolean('is_published')->default(false);
$table->boolean('is_approved')->default(false);

$table->foreignUuid('user_id')->constrained()->onDelete('cascade');
$table->timestamp('published_at')->nullable();
Expand Down