@@ -22,11 +22,14 @@ class InstallPermission extends Command
2222 */
2323 protected $ description = 'Install the CodexShaper Laravel permission ' ;
2424
25+ protected $ seedersPath = __DIR__ .'/../../database/seeds/ ' ;
26+ protected $ routesPath = __DIR__ .'/../../routes/ ' ;
27+
2528 protected function getOptions ()
2629 {
2730 return [
2831 ['force ' , null , InputOption::VALUE_NONE , 'Force the operation to run when in production ' , null ],
29- ['with-dummy ' , null , InputOption::VALUE_NONE , 'Install with dummy data ' , null ],
32+ ['with-demo ' , null , InputOption::VALUE_NONE , 'Install with demo data ' , null ],
3033 ];
3134 }
3235 /**
@@ -95,26 +98,38 @@ public function handle( Filesystem $filesystem)
9598
9699 $ this ->info ('Seeding data into the database ' );
97100
98- // $class = 'PermissionDatabaseSeeder';
101+ $ class = 'PermissionDatabaseSeeder ' ;
102+ $ file = $ this ->seedersPath .$ class .'.php ' ;
103+
104+ if ( file_exists ( $ file ) && !class_exists ($ class )) {
105+ require_once $ file ;
106+ }
107+ with (new $ class ())->run ();
108+
109+ $ this ->info ('Seeding Completed ' );
110+
111+ // $this->call('db:seed', ['--class' => 'PermissionDatabaseSeeder']);
112+
113+ if ($ this ->option ('with-demo ' )) {
114+ $ this ->info ('Adding Demo Routes and resources ' );
115+ $ demo_routes = $ this ->routesPath .'demo.php ' ;
116+ $ original_routes = $ this ->routesPath .'permission.php ' ;
117+ if ( file_exists ($ original_routes ) && file_exists ( $ demo_routes ) ) {
118+ $ original_contents = $ filesystem ->get ($ original_routes );
119+ $ demo_contents = $ filesystem ->get ($ demo_routes );
120+ if (false === strpos ($ original_contents , '/* Demo Routes */ ' )) {
121+ $ filesystem ->append (
122+ $ original_routes ,
123+ "\n\n" .$ demo_contents ."\n"
124+ );
125+ }
126+ }
127+
128+ $ this ->info ('Publishing resources ' );
129+ $ this ->call ('vendor:publish ' , ['--provider ' => PermissionServiceProvider::class, '--tag ' => ['permission.views ' ]]);
130+
131+ }
99132
100- // if (!class_exists($class)) {
101- // require_once $this->seedersPath.$class.'.php';
102- // }
103- // with(new $class())->run();
104-
105- $ this ->call ('db:seed ' , ['--class ' => 'PermissionDatabaseSeeder ' ]);
106-
107- // if ($this->option('with-dummy')) {
108- // $this->info('Publishing dummy content');
109- // $tags = ['dummy_seeds', 'dummy_content', 'dummy_config', 'dummy_migrations'];
110- // $this->call('vendor:publish', ['--provider' => VoyagerDummyServiceProvider::class, '--tag' => $tags]);
111- // $this->info('Migrating dummy tables');
112- // $this->call('migrate');
113- // $this->info('Seeding dummy data');
114- // $this->seed('VoyagerDummyDatabaseSeeder');
115- // } else {
116- // $this->call('vendor:publish', ['--provider' => VoyagerServiceProvider::class, '--tag' => ['config', 'voyager_avatar']]);
117- // }
118133 // $this->info('Setting up the hooks');
119134 // $this->call('hook:setup');
120135 // $this->info('Adding the storage symlink to your public folder');
0 commit comments