i currently have this setup in my routes file
// routes.js
Route.group('dashboard', () => {
Route.get('/', 'DashboardController.index')
Route.resource('blog', 'BlogController')
.addCollection('posts')
}).middleware('auth')
however when visiting /blog/posts no response is returned and the request times out.
i've logged the output of the the collection and it seems to be correct:

alternatively i've tried manually using a callback, e.g. `Route.resource().addCollection([path], [verb], [cb]) and had no luck with that either.
for reference my BlogController looks like this
'use strict'
class BlogController {
/* ... */
* posts (request, response) {
// tried logging from here, nothing.
yield response.sendView('blog/posts')
}
/* ... */
}
When you create a resource, your resource routes are on the top and collections are on the bottom inside an array. So blog/:id takes precedence over /blog/posts, which is wrong.
I will fix the same by adding to the start of the array instead of pushing collections to the array
see issue https://github.com/adonisjs/adonis-framework/issues/334.
juanyunis found solution by creating a url before the resource like this:
Route.get('customers/names', 'CustomerController.names')
Route.resources('customers', 'CustomerController').except('create', 'edit')
Removed addCollection and addMember in 4.0, since they are confusing and adds very little value. So it's better to keep routes easy to scan with eyes, over doing magical stuff
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Most helpful comment
When you create a resource, your resource routes are on the top and collections are on the bottom inside an array. So
blog/:idtakes precedence over/blog/posts, which is wrong.I will fix the same by adding to the start of the array instead of pushing collections to the array