当前位置:网站首页>laravel 定时任务
laravel 定时任务
2022-06-24 19:41:00 【王道长的编程之路】
一、自定义任务方法
php artisan make:command Task
二、自己生成的任务类
protected $signature = 'command:name';//执行任务的名称
public function handle()
{
/* * 这个方法做任务的具体处理,也就是对数据的操作,可用模型 例如我要删除用户表ID为1的用户 * */
DB::table('user')->where('id',1)->delete();
}
三、注册
# 去App\Console\kernel.php
protected $commands = [
//引入新创建的类
\App\Console\Commands\Task::class
];
protected function schedule(Schedule $schedule){
//此处相当于规定同意的定时执行时间,如每分钟分执行以下任务
// command('command:name')写的要与我们刚刚Task文件里的$signature相同
$schedule->command('command:name')->everyMinute();
}
四、运行
php artisan schedule:run
边栏推荐
- Research Report on market supply and demand and strategy of China's solar charging controller industry
- See how sparksql supports enterprise level data warehouse
- 加分利器 不负所托 | 知道创宇获攻防演练防守方感谢信!
- 花房集团二次IPO:成于花椒,困于花椒
- Analyze the implementation process of oauth2 distributed authentication and authorization based on the source code
- 【Laravel系列7.9】测试
- vulnhub Vegeta: 1
- 剑指 Offer 42. 连续子数组的最大和
- The large-scale market of graduate dormitory! Here comes the enviable graduate dormitory!
- Dynamic memory management (1)
猜你喜欢
研究生宿舍大盘点!令人羡慕的研究生宿舍来了!
结合源码剖析Oauth2分布式认证与授权的实现流程
The large-scale market of graduate dormitory! Here comes the enviable graduate dormitory!
ACL (access control list) basic chapter - Super interesting learning network
Analyze the implementation process of oauth2 distributed authentication and authorization based on the source code
别再乱用了,这才是 @Validated 和 @Valid 的真正区别!!!
[laravel series 7.9] test
2022年高处安装、维护、拆除考试模拟100题及模拟考试
机器学习编译入门课程学习笔记第一讲 机器学习编译概述
Dynamic menu, auto align
随机推荐
Simulated 100 questions and online simulated examination of high voltage electrician examination in 2022
Combine pod identity in aks and secret in CSI driver mount key vault
Wechat side: what is consistent hash? In what scenario? What problems have been solved?
New, Huawei cloud Kaitian apaas
结合源码剖析Oauth2分布式认证与授权的实现流程
High level application of SQL statements in MySQL database (I)
find your present (2)
Research and investment strategy report on China's nano silver wire conductive film industry (2022 Edition)
【nvm】
源码阅读 | OpenMesh读取文本格式stl的过程
Common sense of resolution
剑指 Offer 42. 连续子数组的最大和
倍加福(P+F)R2000修改雷达IP
Parental delegation mechanism
Layer 2 and layer 3 forwarding principle based on VLAN
A big factory interview must ask: how to solve the problem of TCP reliable transmission? 8 pictures for you to learn in detail
Do you need to improve your code reading ability? It's a trick
What kind of processor architecture is ARM architecture?
EPICS記錄參考3 -- 所有記錄都有的字段
Dynamic memory management (1)