Reputation: 85
I am creating modules in a modular way.
But there is a problem in defining the new route, and that is that the $router variable does not recognize in the new route.
But if used this way, the problem will be solved: $this->app->router->get()
But I want to use the $router variable like the web.php
route default. Can anyone help?
UserServiceProvider.php
use Illuminate\Support\ServiceProvider;
class UserServiceProvider extends ServiceProvider
{
public function boot()
{
$this->loadRoutesFrom(__DIR__ . '/../Routes/user_route.php');
}
}
user_route.php
/** @var Laravel\Lumen\Routing\Router $router */
//it not work
$router->get('/', function () use ($router) {
return $router->app->version();
});
// it works
$this->app->router->get('module/test', function () {
return 'yohooooo';
});
Upvotes: 0
Views: 217
Reputation: 41
You cannot use the $route variable in your own page. If you are trying to shorten the code, you can try a use as follows.
$route = $this-app->router;
Upvotes: 1