php artisan make:command TaskJoin
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Request;
use App\Models\Task;
use Illuminate\Support\Facades\Redis;
class TaskJoin extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'TaskJoin {task}';
/**
* The console command description.
*
* @var string
*/
protected $description = '用户参与任务';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return int
*/
public function handle()
{
$res = $this->argument('task');
Log::info($this->argument('task'));
}
}
控制器调用
public function test()
{
$res = Task::find(37);
$aa = \Artisan::call('TaskJoin',['task'=>$res]);
}
日志输出结果
[2021-04-24 17:28:32] local.INFO: {"id":37,"user_id":2,"account_id":1,"admin_id":0,"area_id":1,"poster_nickname":"\u9526\u745f","poster_avatar":"https:\/\/thirdwx.qlogo.cn\/mmopen\/vi_32\/Q0j4TwGTfTKr8OKU0oVbZFBuqxXk8yKDAdKJmIcjKBZzKcxcZbJdicicm8hVK65nnSPkV5xeC7bNpKONckNcicpRA\/132","task_type":2,"task_deal_type":3,"price":"3060.00","task_title":"\u514d\u8d39\u9001\u7535\u8111","brand_name":"\u6280\u5609","brand_hidden":0,"task_end_time":1619712000,"task_recruit_num":10,"task_cover":"[\"https:\\\/\\\/tdcm.oss-cn-hangzhou.aliyuncs.com\\\/users\\\/20210423\\\/6XUS6PeseZEoCDhsosyae0U31IQFCNGIP9fyRHR6.jpg\"]","task_fans_limit":0,"extra_imgs":"[\"https:\/\/tdcm.oss-cn-hangzhou.aliyuncs.com\/users\/20210423\/YRdx8JrLYIHOuHvgaar7ONBph2F9iaEDBAjrdXjd.jpg\"]","skill_area":"[\"\u8fd0\u52a8\u5065\u8eab\", \"\u624d\u827a\u6280\u80fd\", \"\u670d\u9970\u978b\u5305\", \"\u7f8e\u5986\"]","contact_img":"[\"https:\\\/\\\/tdcm.oss-cn-hangzhou.aliyuncs.com\\\/users\\\/20210423\\\/QUoQpUWsuH2PcAHsrww48iUElPuejBdwueVUwrBl.jpg\"]","self_quote":0,"is_top":0,"top_end_time":0,"view_num":32,"pay_time":null,"sort":null,"pay_price":"0.00","is_status":0,"task_status":1,"created_at":"2021-04-23T09:04:42.000000Z","updated_at":"2021-04-23T16:00:00.000000Z"}