The order of the commands should be as follows:
-
route:clear -
config:clear -
cache:clear -
view:clear -
optimize:clear -
config:cache -
route:cache
This is because config:cache needs to be run after config:clear to ensure that the cached configuration files are up-to-date. Similarly, route:cache needs to be run after route:clear to ensure that the cached route files are up-to-date.
Here's an updated version of the code with the commands in the correct order:
Route::get('/route-cache', function() {
function makeList($arr)
{
$return = '<ul>';
foreach ($arr as $item)
{
$return .= '<li>' . (is_array($item) ? makeList($item) : $item) . '</li>';
}
$return .= '</ul>';
return $return;
}
$arr = array();
try {
Artisan::call('route:clear');
array_push($arr, Artisan::output());
Artisan::call('config:clear');
array_push($arr, Artisan::output());
Artisan::call('cache:clear');
array_push($arr, Artisan::output());
Artisan::call('view:clear');
array_push($arr, Artisan::output());
Artisan::call('optimize:clear');
array_push($arr, Artisan::output());
Artisan::call('config:cache');
array_push($arr, Artisan::output());
Artisan::call('route:cache');
array_push($arr, Artisan::output());
shell_exec('composer dumpautoload');
} catch(Exception $e) {
print_r($e);
return;
}
return makeList($arr);
});