Skip to content

Commit 5c1a609

Browse files
authored
feat: support for multiple project ids dynamically (#110)
1 parent 7d3c74a commit 5c1a609

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,31 @@ Route::group(function () {
133133
});
134134
});
135135
```
136+
or if you have multiple projects within same workspace in same laravel project you can set project ids dynamically like so:
137+
138+
NOTE: Dynamically set value will always take precedence over value set in .env
139+
140+
```php
141+
Route::middleware(['treblle:project-id-1'])->group(function () {
142+
143+
// YOUR API ROUTES GO HERE
144+
Route::prefix('samples')->group(function () {
145+
Route::get('{uuid}', [SampleController::class, 'view']);
146+
Route::post('store', [SampleController::class, 'store']);
147+
});
148+
149+
});
150+
151+
Route::middleware(['treblle:project-id-2'])->group(function () {
152+
153+
// YOUR API ROUTES GO HERE
154+
Route::prefix('samples')->group(function () {
155+
Route::get('{uuid}', [AnotherSampleController::class, 'view']);
156+
Route::post('store', [AnotherSampleController::class, 'store']);
157+
});
158+
159+
});
160+
```
136161

137162
You're all set. Next time someone makes a request to your API you will see it in real-time on your Treblle dashboard
138163
alongside other features like: auto-generated documentation, error tracking, analytics and API quality scoring.

src/Middlewares/TreblleMiddleware.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,18 @@ final class TreblleMiddleware
2323
/**
2424
* @throws TreblleException
2525
*/
26-
public function handle(Request $request, Closure $next)
26+
public function handle(Request $request, Closure $next, string|null $projectId = null)
2727
{
2828
$ignoredEnvironments = array_map('trim', explode(',', config('treblle.ignored_environments', '') ?? ''));
2929

3030
if (in_array(app()->environment(), $ignoredEnvironments)) {
3131
return $next($request);
3232
}
3333

34+
if (null !== $projectId) {
35+
config(['treblle.project_id' => $projectId]);
36+
}
37+
3438
if (! (config('treblle.api_key'))) {
3539
throw TreblleException::missingApiKey();
3640
}

0 commit comments

Comments
 (0)