Skip to content

Commit

Permalink
Creating route to get tags by namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
nWidart committed Sep 13, 2017
1 parent 3367723 commit 0bacd52
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
28 changes: 28 additions & 0 deletions Modules/Tag/Http/Controllers/Api/TagByNamespaceController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace Modules\Tag\Http\Controllers\Api;

use Illuminate\Http\Request;
use Illuminate\Routing\Controller;
use Modules\Tag\Repositories\TagRepository;
use Modules\Tag\Transformers\TagTransformer;

class TagByNamespaceController extends Controller
{
/**
* @var TagRepository
*/
private $tag;

public function __construct(TagRepository $tag)
{
$this->tag = $tag;
}

public function __invoke(Request $request)
{
$availableTags = $this->tag->allForNamespace($request->get('namespace'));

return response()->json(TagTransformer::collection($availableTags));
}
}
10 changes: 10 additions & 0 deletions Modules/Tag/Http/apiRoutes.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

use Illuminate\Routing\Router;

/** @var Router $router */
$router->get('tags/namespace', [
'as' => 'api.tag.tag.by-namespace',
'uses' => 'TagByNamespaceController',
'middleware' => 'token-can:tag.tags.index',
]);
2 changes: 1 addition & 1 deletion Modules/Tag/Providers/RouteServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@ protected function getBackendRoute()
*/
protected function getApiRoute()
{
return false;
return __DIR__ . '/../Http/apiRoutes.php';
}
}

0 comments on commit 0bacd52

Please sign in to comment.