argument('model'); $model = '\App\Models\\' . Str::camel($name); $nsModel = new $model(); $table = $nsModel->getTable(); $results = DB::select('SHOW COLUMNS FROM ' . $table); $var = '$' . Str::camel($name); $output = $var . ' = new ' . Str::ucfirst($name) . '();' . PHP_EOL; foreach ($results as $result) { $defaultValueForType = $this->getDefaultValueForType($result->Field, $result->Type); if (is_null($defaultValueForType)) { continue; } $output .= $var . '->' . $result->Field . ' = ' . $defaultValueForType . PHP_EOL; } echo $output, PHP_EOL; return 0; } protected function getDefaultValueForType(string $field, string $type) { if (in_array($field, ['created_at', 'updated_at'])) { return null; } if (in_array($field, ['id'])) { return null; } if ($type === 'timestamp') { return 'now();'; } if (Str::contains($type, ['char', 'var', 'text'])) { return '"";'; } if (Str::contains($type, ['int', 'double', 'float'])) { return '0;'; } return null; } }