getAllTableNames(); foreach ($tableNames as $tableName) { // Create the model name by converting the table name to studly case $modelName = Str::studly(Str::singular($tableName)); // Generate the model file content $modelContent = $this->generateModelContent($tableName, $modelName); // Define the path to save the model file $modelFilePath = app_path("Models/{$modelName}.php"); // Save the model file file_put_contents($modelFilePath, $modelContent); echo "Model created for table $tableName.\n"; } echo "Models generation completed.\n"; } /** * Get all table names from the database. * * @return array */ private function getAllTableNames() { $tables = []; // Get the database connection $connection = DB::connection(); // Get the database name $databaseName = $connection->getDatabaseName(); // Query to get all table names in the database $query = "SELECT table_name FROM information_schema.tables WHERE table_schema = '{$databaseName}'"; // Execute the query $results = $connection->select($query); // Extract table names from the results foreach ($results as $result) { $tables[] = $result->table_name; } return $tables; } /** * Generate model content for a given table name and model name. * * @param string $tableName * @param string $modelName * @return string */ private function generateModelContent($tableName, $modelName) { // Retrieve the table's column information $columns = Schema::getColumnListing($tableName); // Generate the model content $content = "