Skip to content

Commit

Permalink
Merge pull request #20 from rupadana/public-api
Browse files Browse the repository at this point in the history
Public api
  • Loading branch information
rupadana authored Feb 9, 2024
2 parents 749f469 + e3040ca commit 174387b
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 3 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,16 @@ To Generate Token, you just need create it from admin panel. It will be Token Re

![Image](https://res.cloudinary.com/rupadana/image/upload/v1704958748/Screenshot_2024-01-11_at_15.37.55_ncpg8n.png)

## Public API

Set API to public by overriding this property on your API Handler. Assume we have a `PaginationHandler`

```php
class PaginationHandler extends Handlers {
public static bool $public = true;
}
```

## TODO

- [ ] Test Plugin for Tenancy purpose
Expand Down
1 change: 0 additions & 1 deletion routes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

Route::prefix('api')
->name('api.')
->middleware('auth:sanctum')
->group(function () {
$panels = Filament::getPanels();

Expand Down
2 changes: 1 addition & 1 deletion src/Commands/MakeApiServiceCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public function handle(): int
]);

$this->components->info("Successfully created API for {$resource}!");
$this->components->info("It automatically registered to '/api-service' route group");
$this->components->info("It automatically registered to '/api' route group");

return static::SUCCESS;
}
Expand Down
21 changes: 20 additions & 1 deletion src/Http/Handlers.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ class Handlers

protected static string $keyName = 'id';

protected static bool $public = false;

const POST = 'post';

const GET = 'get';
Expand All @@ -40,7 +42,24 @@ public static function route(Router $router)
$router
->$method(static::$uri, [static::class, 'handler'])
->name(static::getKebabClassName())
->middleware(static::getMiddlewareAliasName().':'.static::stringifyAbility());
->middleware(static::getRouteMiddleware());
}

public static function isPublic(): bool
{
return static::$public;
}

public static function getRouteMiddleware(): array
{
if (static::isPublic()) {
return [];
}

return [
'auth:sanctum',
static::getMiddlewareAliasName().':'.static::stringifyAbility(),
];
}

protected static function getMiddlewareAliasName()
Expand Down

0 comments on commit 174387b

Please sign in to comment.