Last active
August 22, 2017 12:15
-
-
Save dam1r89/8293ec74773692183b93e5e06144fb95 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace app\Chart; | |
use app\Chart\Http\SomeMiddleware; | |
use Illuminate\Routing\Router; | |
use Illuminate\Support\ServiceProvider; | |
class ChartServiceProvider extends ServiceProvider | |
{ | |
private $namespace = 'dam1r89\Charts\Http\Controller'; | |
private $prefix = 'route-prefix'; | |
public function register() | |
{ | |
$this->publishes([__DIR__ . '/config.php' => config_path('charts.php')], 'charts'); | |
// Commands | |
$this->commands([ | |
Acme\MyCommand::class | |
]); | |
} | |
public function boot() | |
{ | |
// Config | |
$this->mergeConfigFrom(__DIR__ . '/config.php', 'charts'); | |
// Views | |
// Access as view('charts::view.name') | |
$this->loadViewsFrom(__DIR__.'/views', 'charts'); | |
// Migrations | |
if (method_exists($this, 'loadMigrationsFrom')) { | |
// If Laravel 5.3+ | |
$this->loadMigrationsFrom(__DIR__.'/migrations'); | |
} | |
else { | |
$this->publishes([ | |
__DIR__.'/migrations/' => database_path('migrations') | |
], 'chart-migrations'); | |
} | |
// Routes | |
$this->app->call([$this, 'map']); | |
} | |
public function map(Router $router) | |
{ | |
// For middlewares | |
$router->pushMiddlewareToGroup('web', SomeMiddleware::class); | |
// Rroutes | |
$router->group([ | |
'namespace' => $this->namespace, | |
'middleware' => config('charts.middleware'), | |
'prefix' => $this->prefix | |
], function () { | |
require __DIR__ . '/routes.php'; | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment