How can I combine 2 functions in PHP?
I have 2 functions,
function #1
public function cache()
{
$command = 'clear:cache';
try {
Artisan::call($command);
$call = trim(Artisan::output());
return back()->with('success', $call);
} catch (\Exception $e) {
Log::error('Problem running command: ' . $command);
return back()->withErrors('error', ' There was a problem' . $e);
}
}
function #2
public function staticCache()
{
$command = 'clear:static';
try {
Artisan::call($command);
$call = trim(Artisan::output());
return back()->with('success', $call);
} catch (\Exception $e) {
Log::error('Problem running command: ' . $command);
return back()->withErrors('error', ' There was a problem' . $e);
}
}
I've tried this
public function cache()
{
$commandClearCache = 'clear:cache';
$commandClearStatic = 'clear:static';
try {
Artisan::call($commandClearCache, $commandClearStatic);
$call = trim(Artisan::output());
return back()->with('success', $call);
} catch (\Exception $e) {
Log::error('Problem running command: ' . $command);
return back()->withErrors('error', ' There was a problem' . $e);
}
}
But give me an error message: "Type error: Argument 2 passed to Illuminate\Foundation\Console\Kernel::call() must be of the type array, string given, called in /usr/share/nginx/html/statamic/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php on line 217"
Thanks in advance for any help.