Skip to content

Instantly share code, notes, and snippets.

@jakebathman
Last active February 19, 2024 10:28
Show Gist options
  • Star 15 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save jakebathman/15010bcaa72d6d5232dd1c9c19c0a837 to your computer and use it in GitHub Desktop.
Save jakebathman/15010bcaa72d6d5232dd1c9c19c0a837 to your computer and use it in GitHub Desktop.
Remove comments from fresh Laravel files
<?php
/*
|--------------------------------------------------------------------------
| Remove Laravel Comments
|--------------------------------------------------------------------------
|
| Just made a new Laravel project, but don't want all those big
| comment blocks? Put this in the root of your project and run
| "php remove_laravel_comments.php"
|
*/
$directories = [
'app',
'bootstrap',
'config',
'database',
'public',
'resources',
'routes',
];
$base = './';
foreach ($directories as $dir) {
$it = new RecursiveDirectoryIterator($base . $dir);
foreach (new RecursiveIteratorIterator($it) as $file) {
if ($file->getExtension() == 'php') {
echo "Removing comments from: " . $file->getRealPath() . "\n";
$contents = file_get_contents($file->getRealPath());
$new = preg_replace('/^(\{?)\s*?\/\*(.|[\r\n])*?\*\/([\r\n]+$|$)/im', '$1', $contents);
file_put_contents($file->getRealPath(), $new);
}
}
}
@GraxMonzo
Copy link

Thanks Jake!

@prajwal89
Copy link

how much difference do you get after using this in terms of size

@GraxMonzo
Copy link

@prajwal89 This does not affect the size of the application, but rather for space on screen.

@mustafaerpek
Copy link

Thank you Jake!

@lewislarsen
Copy link

You're a superstar, thanks a bunch! Starred.

@MrHDOLEK
Copy link

MrHDOLEK commented Nov 6, 2023

Thanks @jakebathman

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment