Skip to content

Commit babb1f0

Browse files
authored
Merge pull request #586 from atmonshi/article-api
adding Article API
2 parents 8eac585 + 311fb98 commit babb1f0

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
namespace App\Http\Controllers\Api;
4+
5+
use App\Http\Controllers\Controller;
6+
use App\Models\Article;
7+
8+
class ArticleController extends Controller
9+
{
10+
public function index()
11+
{
12+
return Article::paginate();
13+
}
14+
15+
public function show(Article $article)
16+
{
17+
return $article->append('stars_count');
18+
}
19+
}

routes/api.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?php
22

3+
use App\Http\Controllers\Api\ArticleController;
34
use App\Http\Controllers\Api\AuthorController;
45
use App\Http\Controllers\Api\PluginController;
56
use Illuminate\Support\Facades\Route;
@@ -9,3 +10,6 @@
910

1011
Route::get('authors', [AuthorController::class, 'index']);
1112
Route::get('authors/{author:slug}', [AuthorController::class, 'show']);
13+
14+
Route::get('articles', [ArticleController::class, 'index']);
15+
Route::get('articles/{article:slug}', [ArticleController::class, 'show']);

0 commit comments

Comments
 (0)