一: app\Console\Commands目录下创建脚本文件TestConsole.php
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use App\Base\CommonPoolMethod;
class TestConsole extends Command
{
use CommonPoolMethod;
protected $signature = 'update:test_function';
protected $description = "更新测试方法";
public function __construct()
{
parent::__construct();
}
public function handle()
{
}
}
二:laravel根目录下执行artisan命令【php artisan update:test_function】
注:执行命令报错【SQLSTATE[HY000] [2002] No such file or directory 】 原因:未找不到mysql.sock文件 解决: 1:打开MySQL管理工具,执行sql语句 【show variables like ‘%sock%’】,得到一个目录【/Applications/MAMP/tmp/mysql/mysql.sock】
2:找到 ./config/database.php 中的 unix_socket,修改【‘unix_socket’ => ‘/Applications/MAMP/tmp/mysql/mysql.sock’】
或者
.env中对应的DB_SOCKET=/Applications/MAMP/tmp/mysql/mysql.sock
|