Skip to content

Commit 7c26514

Browse files
author
Arko Elsenaar
committed
Adds packages.json feed to API
1 parent c5d1a4f commit 7c26514

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

Diff for: app/Http/Controllers/Api/FeedController.php

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
namespace App\Http\Controllers\Api;
4+
5+
use App\Http\Controllers\Controller;
6+
use App\Package;
7+
8+
class FeedController extends Controller
9+
{
10+
public function __invoke()
11+
{
12+
return cache()->remember('all-packages-as-json', 3600, function () {
13+
return Package::query()
14+
->with(['tags', 'author'])
15+
->get()
16+
->map(function ($package) {
17+
return [
18+
'name' => $package->display_name,
19+
'author' => $package->author->name,
20+
'abstract' => $package->abstract,
21+
'url' => route('packages.show', [
22+
'namespace' => $package->composer_vendor,
23+
'name' => $package->composer_package,
24+
]),
25+
'tags' => $package->tags->pluck('name'),
26+
];
27+
});
28+
});
29+
}
30+
}

Diff for: routes/api.php

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
Route::get('popular', Api\PopularController::class)->middleware('throttle:60')->name('api.popular-packages');
99
Route::get('stats', Api\StatsController::class)->middleware('throttle:60');
1010

11+
Route::get('packages.json', Api\FeedController::class)->middleware('throttle:60');
12+
1113
Route::middleware('auth:api')->group(function () {
1214
Route::get('packages', Api\PackagesController::class);
1315
});

0 commit comments

Comments
 (0)