<?php

namespace @@packageNamespace@@;
use Illuminate\Support\ServiceProvider as BaseServiceProvider;
use Illuminate\Support\Facades\Gate;

/**
 * Class ServiceProvider
 * @package LaraCrud
 */

class ServiceProvider extends BaseServiceProvider
{

    protected $defer = false;

    /**
     * List of command which will be registered.
     * @var array
     */
    protected $commands = [];

    /**
     * The policy mappings for the application.
     *
     * @var array
     */
    protected $policies = [
      //  'App\Model' => 'App\Policies\ModelPolicy',
    ];

    /**
     * Perform post-registration booting of services.
     *
     * @return void
     */
    public function boot()
    {
        $this->loadRoutesFrom(__DIR__ . '/../routes/web.php');
         $this->registerPolicies();
    }

    /**
     * Register bindings in the container.
     *
     * @return void
     */
    public function register()
    {
      $this->loadViewsFrom(__DIR__ . '/../resources/views', '@@packageName@@');
            $this->mergeConfigFrom(
                __DIR__ . '/../config/@@packageName@@.php', '@@packageName@@'
            );

         if ($this->app->runningInConsole()) {
                $this->commands($this->commands);
                $this->publishes([
                            __DIR__ . '/../config/package.php' => config_path('@@packageName@@.php'),
                        ],'@@packageName@@-config');

                        $this->publishes([
                            __DIR__ . '/../resources/views' => resource_path('views/vendor/@@packageName@@'),
                        ],'@@packageName@@-views');

                        $this->loadMigrationsFrom(__DIR__ . '/../database/migrations');
                }

    }

     /**
     * To register laracrud as first level command. E.g. laracrud:model
     *
     * @return array
     */
    public function provides()
    {
        return ['@@packageName@@'];
    }

     /**
      * Register the application's policies.
      *
      * @return void
      */
    public function registerPolicies()
    {
            foreach ($this->policies as $key => $value) {
                Gate::policy($key, $value);
            }
        }
}