当前位置:网站首页>laravel框架中 定时任务的实现
laravel框架中 定时任务的实现
2022-06-27 16:27:00 【我想有只小可爱】
生成命令
你可以使用 Artisan 命令 make:command 来创建一个新的命令。make:command 命令会在 app/Console/Commands 目录中创建一个新的命令类。如果该目录不存在,它会在你第一次运行 make:command 命令时自动创建。生成的命令将包含所有命令中默认存在的属性和方法。
————————————————
原文作者:Laravel China 社区文档:《Laravel 8 中文文档(8.x)》
转自链接:https://learnku.com/docs/laravel/8.x/artisan/9387#2fe472
版权声明:翻译文档著作权归译者和 LearnKu 社区所有。转载
php artisan make:command SendEmails 
代码:
<?php
namespace App\Console\Commands;
use App\Models\exam1\Pin;
use Illuminate\Console\Command;
class SendEmail extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'sendEmail';
/**
* The console command description.
*
* @var string
*/
protected $description = 'sendEmail';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return int
*/
public function handle()
{
Pin::insert([
'uid'=>3,
'desc'=>'描述',
'sid'=>11
]);
}
}在 app/Cosole/Kernel.php

<?php
namespace App\Console;
use App\Console\Commands\SendEmail;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
class Kernel extends ConsoleKernel
{
protected $commands=[
SendEmail::class
];
/**
* Define the application's command schedule.
*
* @param \Illuminate\Console\Scheduling\Schedule $schedule
* @return void
*/
protected function schedule(Schedule $schedule)
{
$schedule->command('sendEmail')->everyMinute();
}
/**
* Register the commands for the application.
*
* @return void
*/
protected function commands()
{
$this->load(__DIR__.'/Commands');
require base_path('routes/console.php');
}
}运行命令:
php artisan schedule:work效果:

边栏推荐
- Explain in detail the differences between opentsdb and tdengine in system functions
- 2022年信创行业空间测算
- 新产品新人事新服务,英菲尼迪继续深耕中国未来可期!
- Asemi rectifier bridge kbp307 parameters, kbp307 details, kbp307 pictures
- 如何制作登录界面
- Shardingsphere & Atlas & MYCAT comparison
- Market status and development prospect of 4-butyl resorcinol used in skin care industry in the world in 2022
- TP5 generates the most detailed two-dimensional code tp6 (also available)
- 手把手教你在Windows 10安装Oracle 19c(详细图文附踩坑指南)
- Allocate aligned heap space
猜你喜欢

原创 | 2025实现“5个1”奋斗目标!解放动力全系自主非道路国四产品正式发布

Wanzhou gold industry: what are the differences between gold t+d investment and other investments?

SQL update批量更新

How to use the low code platform of the Internet of things for picture management?

SQL update batch update

Contest3182 - the 39th individual training match for 2021 freshmen_ E: ringring

Anfulai embedded weekly report (issue 252): February 7, 2022 to February 13, 2022
![[webinar] mongodb and Google cloud accelerate enterprise digital innovation](/img/ea/4680381ce78fd5d956ed009692b424.png)
[webinar] mongodb and Google cloud accelerate enterprise digital innovation

TP5 restrict access frequency

Tdengine connector goes online Google Data Studio store
随机推荐
Seata server database connection user and service database undo_ What permissions do log users need?
产学合作协同育人,麒麟软件携手南开大学合力完成《软件测试与维护》实践课程
Shardingsphere & Atlas & MYCAT comparison
Application of tdengine in monitoring of CNC machine tools
Contest3182 - the 39th individual training match for 2021 freshmen_ F: ss
Explain in detail the differences between opentsdb and tdengine in system functions
About binary
Control file related views
Mise à jour SQL mise à jour par lots
How to use the low code platform of the Internet of things for picture management?
Written in eclipse, problems after querying the database connection
[UVM foundation] can only be used in build_ Research on executing instantiation action in phase
Teach you to use elastic search: run the first hello world search command
The first in China! EMQ joined Amazon cloud technology's "startup acceleration - global partner network program"
MFS分布式文件系统
【ELT.ZIP】OpenHarmony啃论文俱乐部—见证文件压缩系统EROFS
Wanzhou gold industry: what knowledge points do you need to master to invest in precious metals?
Why migrate from opentsdb to tdengine
校园书籍资源共享平台
如何查看 MySQL 表的索引信息?