当前位置:网站首页>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效果:

边栏推荐
- 电脑安全证书错误怎么处理比较好
- Using WebDAV instead of 445 port file share
- Contest3182 - the 39th individual training match for 2021 freshmen_ F: ss
- 为什么要从 OpenTSDB 迁移到 TDengine
- How to arrange digital collections on online platforms such as reading and Chinese online? Will "read/write-to-earn" products be launched in the future?
- Teach you how to realize pynq-z2 bar code recognition
- 国内首家!EMQ加入亚马逊云科技“初创加速-全球合作伙伴网络计划”
- The power of code refactoring: how to measure the success of refactoring
- 喜讯丨英方软件2022获得10项发明专利!
- Hikvision tools manager Hikvision tools collection (including sadp, video capacity calculation and other tools) a practical tool for millions of security practitioners
猜你喜欢

How to create a login interface

如何制作登录界面

Analysis of shardingsphere core source code

The power of code refactoring: how to measure the success of refactoring

PostgreSQL数据库WAL——资源管理器RMGR

How much room does Migu video have for development without relying on sports events?

JS event binding and common events

Using WebDAV instead of 445 port file share

Control file related views

推荐几个开源的物联网平台
随机推荐
Two methods of MySQL database login and logout
Market status and development prospect of 4-butyl resorcinol used in skin care industry in the world in 2022
实现时序数据库(Time Series Database)在特定场景下“远超”通用数据库的难点
Rxjs mergeMap 的使用场合
Market status and development prospect forecast of global epoxy resin active toughener industry in 2022
IDEA 官网插件地址
Using WebDAV instead of 445 port file share
Wechat applet payment countdown
Current market situation and development prospect forecast of global concrete shrinkage reducing agent industry in 2022
Shardingsphere sharding proxy actual combat scenario
Redis Series 2: data persistence improves availability
Contest3182 - the 39th individual training match for 2021 freshmen_ F: ss
Offline disk group
Hikvision Tools Manager海康威视工具大全(含SADP、录像容量计算等工具)百万安防从业者的实用工具
TDengine在数控机床监控中的应用
Oracle的NUMBER长度超过19之后,实体使用Long映射,导致出现问题是为什么?
国信证券是国企吗?在国信证券开户资金安全吗?
The incluxdb cluster function is no longer open source, and the tdengine cluster function is even better
时间序列数据的特点
Mise à jour SQL mise à jour par lots