API Folders

Posted 3 years ago by stueynet

So my app is about 90% there. On the web it works great. Nice and clean. I'm very happy with it and all of its Eloquent and blade glory.

So next I am going to build out the API for the mobile app version. My question is how I should organize my files for the API and how I implement those via the routes file.

So I have a nice route group set up

Route::group(['prefix' => 'api/v1', 'middleware' => 'auth'], function()
    Route::get('posts', 'ApiController@index');

That works great if ApiController is in my Http/Controllers directory. However I want all my API stuff in its own directory. So Http\Controllers\Api\V1\Posts\PostsApiController.php

I am really miffed about how one would do this. First off how to I adjust the routes file so it is not looking in the top level of Controllers/ for those api routes. Then what exactly is the namespacing requirements on those new Controllers in the subfolders.

Sorry I know this is noob central.

Please sign in or create an account to participate in this conversation.