php - Laravel package controller alias in routes -


i'm trying create package in laravel 5.2 routes. have controller in http/controllers folder (with namespace vendor\package\http\controllers\mycontroller). want create alias don't know how. don't want call controller in routes.php that:

route::get('myurl', vendor\package\http\controllers\mycontroller::class . '@action'); 

but that:

route::get('myurl', 'mycontroller@action'); 

i tried search in application class api can't find information.

this code in package provider doesn't work.

$this->app      ->alias(vendor\package\http\controllers\mycontroller::class, 'mycontroller'); 

my service provider:

class packagerouterserviceprovider extends serviceprovider {     /**      * bootstrap application services.      *      * @return void      */     public function boot()     {         //     }      /**      * register application services.      *      * @return void      */     public function register()     {         include(__dir__ . '/../http/routes.php');          $this->app->alias(mycontroller::class, 'mycontroller'); // <- tried     } } 

try update packagerouterserviceprovider.php this:

class packagerouterserviceprovider extends serviceprovider {     // set namespace package controllers namespace.     protected $namespace = 'vendor\package\http\controllers';      public function boot(router $router)     {         //     }      public function register()     {         $this->maproutes($this->app->router);     }      protected function maproutes(router $router)     {         $router->group(['namespace' => $this->namespace], function($router) {             require (__dir__ . '/../http/routes.php');         });     } } 

of course, need register provider in laravel config app.php file in order work.


Comments

Popular posts from this blog

sequelize.js - Sequelize group by with association includes id -

android - Robolectric "INTERNET permission is required" -

java - Android raising EPERM (Operation not permitted) when attempting to send UDP packet after network connection -