Skip to content

Instantly share code, notes, and snippets.

@Mombuyish
Last active February 23, 2020 09:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Mombuyish/472ef7c5931566d648d856102a0085c1 to your computer and use it in GitHub Desktop.
Save Mombuyish/472ef7c5931566d648d856102a0085c1 to your computer and use it in GitHub Desktop.
<?php
//Illuminate\Foundation\Console\ConfigCacheCommand
public function handle()
{
$this->call('config:clear'); // clear your config cached if it exists.
$config = $this->getFreshConfiguration(); // get a new config
$configPath = $this->laravel->getCachedConfigPath(); // get cache file path
$this->files->put(
$configPath, '<?php return '.var_export($config, true).';'.PHP_EOL
); // put the cached file.
try {
require $configPath; // if it generated successful, require the file.
} catch (Throwable $e) { // php7 error exception handle.
$this->files->delete($configPath); // delete failed file.
// throwing a logic exception to tell you, oh, something wents wrong.
throw new LogicException('Your configuration files are not serializable.', 0, $e);
}
// otherwise it's successful.
$this->info('Configuration cached successfully!');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment