-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Installation #11
Comments
Ah, actually that's a good point. They probably won't show up in that
|
LMAO damn, okay that helps a little bit (not sure why i didnt think to hit the url myself to check XD) |
Good point you raised though. I might have to roll a custom api:routes
|
Curiously, can you have multiple Route::api() blocks and have it register it all of them? |
You can, yes. Usually you'd have a single group per version.
|
Yeah Im trying to split my application up into modules, which means each module has its own set of routes, its own version/extension on the api and be able to consume the api from within also...but all im getting is a crap load of problems with it :( |
Hm, I'd be inclined to keep them all the same version and only make a new
|
okay for eg, This project is gonna have the following modules (eg) forum/ each module will have its own api and routes setup, so really they all need to have their own Route::api() block |
Yeah you can reuse the same version in multiple groups. Unless you've tried
|
Okay ive been playing around, and before installing the package, i could see the following routes
After adding the alias's back and renaming |
Paste your routes file.
|
// routes-api.php
<?php
// if the request matches the route group, or we are in console(easier to debug), add the routes
if (Request::is(\Config::get('core::routes.paths.api', 'api').'/*') || App::runningInConsole()) {
Route::api(['version' => 'v1', 'prefix' => \Config::get('core::routes.paths.api', 'api')], function () use ($namespace) {
$namespace .= '\Api\V1';
// add forum resources, such as categories and threads
Route::api(['prefix' => 'forum'], function () use ($namespace) {
Route::api(['prefix' => '{category}'], function () use ($namespace) {
Route::get('/', ['as' => 'pxapi.forum.category.view', 'uses' => $namespace.'\CategoryController@viewCategory']);
});
Route::get('/', ['as' => 'pxapi.forum.category.index', 'uses' => $namespace.'\CategoryController@getCategories']);
});
});
} // routes-module.php
<?php
// if the request matches the route group, or we are in console(easier to debug), add the routes
// if (Request::is('forum/*') || App::runningInConsole()) {
Route::group(['prefix' => 'forum'], function () use ($namespace) {
$namespace .= '\Module';
// categories
Route::group(['prefix' => '{category_name}'], function () use ($namespace) {
// threads
Route::group(['prefix' => '{thread_name}.html'], function () use ($namespace) {
Route::get('/', ['as' => 'pxcms.forum.thread.index', 'uses' => $namespace.'\ThreadController@getThread']);
});
Route::get('/', ['as' => 'pxcms.forum.category.index', 'uses' => $namespace.'\CategoryController@getCategory']);
});
Route::get('/', ['as' => 'pxcms.forum.index', 'uses' => $namespace.'\CategoryController@getCategories']);
});
// } Both get included by a |
I'll have a look at this properly when I'm at my computer. You should
|
i tried that, didnt like it XD // running api/forum
ErrorException
Argument 1 passed to Dingo\Api\Http\Response::makeFromExisting() must be an instance of Illuminate\Http\Response, instance of Illuminate\Http\JsonResponse given, called in /Users/danaldridge/Sites/cysha/vendor/dingo/api/src/Routing/Router.php on line 138 and defined
(
12. ErrorException
…/vendor/dingo/api/src/Http/Response.php25
) // running forum/
RuntimeException
There is no API collection for the version "v1". |
Any idea when you could have a look at this? |
I'm still unable to recreate this. I have the following routes: Route::api(['version' => 'v1', 'prefix' => 'api'], function()
{
Route::group(['prefix' => 'forum'], function()
{
Route::get('/', 'ForumApiController@index');
});
});
Route::group(['prefix' => 'forum'], function()
{
Route::get('/', 'ForumController@index');
}); BOTH controllers are extending from |
okay gonna go try it again been a few hours since, but it is 3am now so hrm XD |
Okay gone through the install again, can get to forum/ which seems to want to 404 if i have the API::get() call in there o.O on the api route itself i get Argument 1 passed to Dingo\Api\Http\Response::makeFromExisting() must be an instance of Illuminate\Http\Response, instance of Illuminate\Http\JsonResponse given, called in /Users/danaldridge/Sites/cysha/vendor/dingo/api/src/Routing/Router.php on line 138 and defined My routes file now looks like this... <?php
$namespace = 'Cysha\Modules\Forum\Controllers';
// require_once 'routes-admin.php';
// require_once 'routes-api.php';
// require_once 'routes-module.php';
Route::api(['version' => 'v1', 'prefix' => 'api'], function () use ($namespace) {
Route::group(['prefix' => 'forum'], function () use ($namespace) {
$namespace .= '\Api\V1';
Route::get('/', $namespace.'\CategoryController@getCategories');
});
});
Route::group(['prefix' => 'forum'], function () use ($namespace) {
$namespace .= '\Module';
Route::get('/', $namespace.'\CategoryController@getCategories');
}); and checking artisan routes shows the module route $ art routes
+--------+-------------------------+----------------------+-------------------------------------------------------------------------+----------------+---------------+
| Domain | URI | Name | Action | Before Filters | After Filters |
+--------+-------------------------+----------------------+-------------------------------------------------------------------------+----------------+---------------+
| | GET|HEAD _debugbar/open | debugbar.openhandler | Closure | | |
| | GET|HEAD forum | | Cysha\Modules\Forum\Controllers\Module\CategoryController@getCategories | | |
+--------+-------------------------+----------------------+-------------------------------------------------------------------------+----------------+---------------+ |
What are you returning from this API route? |
Just some json. I know that works without the api stuff running, or do I just return the array and let it do its stuff? |
Yeah don't return a JSON response. Return a regular array or object. |
Okay so the API side works now, doing public function getCategories()
{
$api = API::get('api/forum');
dd($api);
} im getting a 404 on the |
You don't need to specify the prefix. Just |
Holy crap, that took a lot longer than it should have, thanks so much for your help :D now, back to some real coding ^^ |
No worries! If you haven't already I suggest you read through the Wiki. I'll hopefully be doing a few screencasts on it in the coming week. 😄 |
Impressively i did, i think cause i went through about 4/5 different packages that supposidly did the same thing, It was just melting my brain :3 ill have another look though the wiki a bit later and maybe submit some changes perhaps |
Instead of using the existing Laravel router we will use a new instance. This should prevent the APIs internal dispatcher from overriding the current route on the actual Laravel router instance. There does not seem to be any need for the router instance that is injected into the adapter to be the actual Laravel router, as the adapter just needs an instance to dispatch the API-only routes.
Okay so i have installed the package and all that jazz, looks like its working fine. Problem i have is thusly...
So thats supposed to create a route on api/test that will return some json correct?
So anyway, i run 'php artisan routes' only to not see that route atall?
Am i doing something wrong or what? Any help is greatly appreciated... currently using laravel 4.1.25
The text was updated successfully, but these errors were encountered: