Skip to content

Commit

Permalink
Fix CB Seeder not found
Browse files Browse the repository at this point in the history
  • Loading branch information
Ferry Ariawan committed Jun 18, 2021
1 parent 450bcb3 commit 044c99c
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 8 deletions.
21 changes: 21 additions & 0 deletions src/CRUDBoosterServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

use crocodicstudio\crudbooster\commands\CrudboosterVersionCommand;
use crocodicstudio\crudbooster\commands\Mailqueues;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\Validator;
use Illuminate\Support\ServiceProvider;
use crocodicstudio\crudbooster\commands\CrudboosterInstallationCommand;
Expand All @@ -27,6 +28,7 @@ public function boot()
$this->loadRoutesFrom(__DIR__.'/routes.php');

if($this->app->runningInConsole()) {
$this->registerSeedsFrom(__DIR__.'/database/seeds');
$this->publishes([__DIR__.'/configs/crudbooster.php' => config_path('crudbooster.php')],'cb_config');
$this->publishes([__DIR__.'/userfiles/controllers/CBHook.php' => app_path('Http/Controllers/CBHook.php')],'CBHook');
$this->publishes([__DIR__.'/userfiles/controllers/AdminCmsUsersController.php' => app_path('Http/Controllers/AdminCmsUsersController.php')],'cb_user_controller');
Expand Down Expand Up @@ -89,6 +91,25 @@ private function registerSingleton()
});
}

protected function registerSeedsFrom($path)
{
foreach (glob("$path/*.php") as $filename)
{
include $filename;
$classes = get_declared_classes();
$class = end($classes);

$command = request()->server('argv', null);
if (is_array($command)) {
$command = implode(' ', $command);
if ($command == "artisan db:seed") {
Artisan::call('db:seed', ['--class' => $class]);
}
}

}
}

private function customValidation() {
Validator::extend('alpha_spaces', function ($attribute, $value) {
// This will only accept alpha and spaces.
Expand Down
4 changes: 0 additions & 4 deletions src/commands/CrudboosterInstallationCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,6 @@ public function handle()

$this->info('Migrating database...');

if (! class_exists('CBSeeder')) {
require_once __DIR__.'/../database/seeds/CBSeeder.php';
}

$this->call('migrate');
$this->call('db:seed', ['--class' => 'CBSeeder']);
$this->call('config:clear');
Expand Down
3 changes: 0 additions & 3 deletions src/commands/CrudboosterUpdateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,6 @@ public function handle()
$this->info('Migrating database...');
$this->call('migrate');

if (! class_exists('CBSeeder')) {
require_once __DIR__.'/../database/seeds/CBSeeder.php';
}
$this->call('db:seed', ['--class' => 'CBSeeder']);

$this->info('Clearing Cache...');
Expand Down
2 changes: 1 addition & 1 deletion src/database/seeds/CBSeeder.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
//namespace Database\Seeders; Fix: Target class [CBSeeder] does not exist.
namespace Database\Seeders;

use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
Expand Down

0 comments on commit 044c99c

Please sign in to comment.