/** * Make source file .. * * @param Command $command * @throws SeederException * @return bool|mixed */ public function create(Command $command) { $path = self::getConfig('path'); if (!File::isWritable($path)) { throw new SeederException('Path are not writable. Please chmod!'); } $source = explode(',', self::getSource()); array_walk($source, function ($name) use($path, $command) { $model = 'App\\' . ucfirst(strtolower($name)); if (!isEloquentExists($model)) { $command->error(sprintf('Model %s not exists. Skipped!', $model)); return false; } $fullPath = getFullPathSource($name, $this); if (File::exists($fullPath)) { $command->error(sprintf('Model %s already exists. Skipped!', $name)); return false; } File::put($fullPath, arrayToYaml(['class' => ucfirst($name), 'source' => arrayToYaml(getTableSchema($model), 1)], 1)); $command->info(sprintf('File %s created successfully!', $name)); }); }
/** * Rollback models ... * * @param array $revert */ private function rollbackProcessing(array $revert) { array_walk($revert, function ($model) { if (isEloquentExists(str_singular($model))) { $table = self::getTable(str_singular($model)); DB::table($table->getTable())->delete(); } return false; }); }