Creating route to get tags by namespace

parent 33677230
<?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));
}
}
<?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',
]);
......@@ -33,6 +33,6 @@ class RouteServiceProvider extends CoreRoutingServiceProvider
*/
protected function getApiRoute()
{
return false;
return __DIR__ . '/../Http/apiRoutes.php';
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment