nodes
132
4
General

[L5] Extending/Rebind Router or custom route group

Posted 4 years ago by nodes

Hi,

As a few others have written about here on the forum, I also have some issues with the new Laravel 5 router. I've looked through the other topics but none seem to have an answer for my issue.

In Laravel 4.2 it was rather easy to "replace/rebind" the default router. There I was able to make a router that extended the router which gave me the opportunity to e.g. create custom route groups. Like.

Route::api(options, function {})

Which is basically an alias for an ordinary route group, but which would be treated differently and sent to a different Response class, so it always returned JSON, exceptions were handled accordingly to the API etc.

This is basically the same idea I would like to get going with Laravel 5. Since L5 is still rather new I haven't been able to find any articles, blog posts or guides to how you would be able to extend the new L5 core. Because of this I have been tinkering around and trying stuff here and there.

I seem be able to replace the default router with my custom one. And also registering all my routes to my new router as well. But where I keep hitting my head against the wall is that the request will not USE my custom router.

And as far as I see it's because Illuminate\Foundation\Http\Kernel's constructor always injects an Illuminate router into it's constructor. So basically all requests will be handled within an Illuminate router no matter how much rebinding you're doing.

/**
 * Create a new HTTP kernel instance.
 *
 * @param  \Illuminate\Contracts\Foundation\Application  $app
 * @param  \Illuminate\Routing\Router  $router
 * @return void
 */
public function __construct(Application $app, Router $router)

Does anyone have had any luck or found a solution for this? Or has it been done like this, so you would never be able to extend/rebind the default router?

If it's not possible to extend/rebind the default router, does anyone have any suggestion/ideas to how you could make some form of Route group/alias where routes inside that would be treated in a different way than the default one? :)

I hope my question(s) make sense and that someone would be of assistance :)

Regards,

Morten

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

Reply to

Use Markdown with GitHub-flavored code blocks.