artisan php: command not found,用Laravel的artisan命令执行php脚本

论坛 期权论坛 编程之家     
选择匿名的用户   2021-6-2 16:57   1766   0

平时开发过程中经常碰到写个数据处理脚本,统计脚本的情况,都需要在Laravel项目的环境下执行,而官方提供的artisan命令却不支持直接执行php脚本文件,这里记录下自己做的一个Command,用来解决这类问题。//1.使用命令行创建文件

php artisan make:command RunFile

//2.将一下内容粘贴到RunFile文件中

namespace App\Console\Commands;

use Illuminate\Console\Command;

use Symfony\Component\Console\Input\InputArgument;

class RunFile extends Command

{

/**

* The console command name.

*

* @var string

*/

protected $name = 'run';

/**

* The console command description.

*

* @var string

*/

protected $description = 'Run php file with system env support.';

/**

* Execute the console command.

*

* @return mixed

*/

public function handle()

{

$file = $this->argument('php_file');

if (is_file($file)) {

include $file;

} else {

$this->error("file '{$file}' not found!");

}

}

/**

* Get the console command arguments.

*

* @return array

*/

protected function getArguments()

{

return array(

array('php_file', InputArgument::REQUIRED, 'The php file to run with Laputa.'),

);

}

}

//3.测试运行php artisan run [完整的路径]

php artisan run /home/vagrant/Code/library_site/site/app/Utils/Tools.php

分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:3875789
帖子:775174
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP