在 laravel ( v9 ) 專案中,我嘗試啟動一些 bash 命令,如下所示
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Symfony\Component\Process\Process;
use Carbon\Carbon;
class SaveLog extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'eraselog';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Save current log and erase old log';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return int
*/
public function handle()
{
$copy = new Process(['cp storage/logs/laravel.log storage/logs/laravel_new.log']);
$erase = new Process([' > storage/logs/laravel.log']);
$copy->run();
$erase->run();
}
}
問題:命令不起作用。也許這不是啟動此命令的正確方法。那么,有人展示了正確的方法嗎?
uj5u.com熱心網友回復:
你可以使用 Laravel 檔案存盤命令:
Storage::disk('logs')->copy('laravel.log', 'laravel_new.log');
Storage::disk('logs')->delete('laravel.log');
您需要在“config/filesystems.php”中添加一個新的“磁盤”:
'disks' => [
'logs' => [
'driver' => 'logs',
'root' => storage_path('logs'),
],
],
Laravel 檔案:https ://laravel.com/docs/9.x/filesystem#copying-moving-files
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/425326.html
標籤:拉拉维尔
上一篇:如何在LaravelMix中創建和配置多個Vue實體?
下一篇:Laravel9-laravelnew命令有錯誤:已棄用:Symfony\Component\Process\Process::getIterator(int$flags=0)的回傳型別
