Skip to content

Instantly share code, notes, and snippets.

@dam1r89
Last active August 22, 2017 12:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dam1r89/8293ec74773692183b93e5e06144fb95 to your computer and use it in GitHub Desktop.
Save dam1r89/8293ec74773692183b93e5e06144fb95 to your computer and use it in GitHub Desktop.
<?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