当前位置:网站首页>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
边栏推荐
- 糖豆人登录报错解决方案
- 2022年安全员-A证考题及答案
- Leetcode algorithm refers to offer II 027 Palindrome linked list
- 是否需要提高代码阅读能力?这有技巧
- 2022-06-10 work record --js- obtain the date n days after a certain date
- Research Report on market evaluation and investment direction of Chinese dermatology drugs (2022 Edition)
- Analyze the implementation process of oauth2 distributed authentication and authorization based on the source code
- 【武汉大学】考研初试复试资料分享
- Are you afraid of being asked MySQL related questions during the interview? This 30000 word essence summary + 100 interview questions, and it's enough to hang the interviewer
- LeetCode Algorithm 剑指 Offer 52. 两个链表的第一个公共节点
猜你喜欢

2022年高压电工考试模拟100题及在线模拟考试

Leetcode: calculate the number of elements less than the current element on the right (sortedlist+bisect\u left)

Cases of addition, deletion, modification and search of C # learning for two years and C # import and export (de duplication)

2022安全员-B证考试题库及答案

Canvas to add watermark to pictures

EPICS记录参考4--所有输入记录都有的字段和所有输出记录都有的字段

vulnhub Vegeta: 1

Tech Talk 活动回顾|云原生 DevOps 的 Kubernetes 技巧

环境配置 | VS2017配置OpenMesh源码和环境

2022年安全员-A证考题及答案
随机推荐
[text data mining] Chinese named entity recognition: HMM model +bilstm_ CRF model (pytoch) [research and experimental analysis]
2022-06-16 work record --js- judge the number of digits in string type digits + judge the number of digits in numeric type digits + limit the text length (display n words at most, exceeding...)
[untitled]
Analyze the implementation process of oauth2 distributed authentication and authorization based on the source code
[laravel series 7.9] test
Development specification - parameter verification exception, exception return prompt section
vulnhub DC: 2
Attention, postgraduate candidates! They are the easiest scams to get caught during the preparation period?!
Tech Talk 活动回顾|云原生 DevOps 的 Kubernetes 技巧
Environment configuration | vs2017 configuring openmesh source code and environment
win10或win11打印机无法打印
Leetcode: calculate the number of elements less than the current element on the right (sortedlist+bisect\u left)
Basic principles of layer 2 switching
Learning bit segment (1)
Common sense of resolution
The difference between interceptor and filter
JD 618 conference tablet ranking list announced that the new dark horse brand staff will compete for the top three, learning from Huawei, the leader of domestic products
Leetcode: push domino (domino simulation)
[postgraduate entrance examination English] prepare for 2023, learn list9 words
Dynamic memory management (1)