dra11767 2018-08-16 10:47
浏览 24
已采纳

使用发送邮件安排呼叫并登录Laravel

How to make notification message if some user's 'deleted_at' field is 'null' when daily check? When occurred that case, I wish to send a email message with that user's name to admin.

// app/console/Kernel.php

    protected function schedule(Schedule $schedule)
    {
        $schedule->call(function () {
            $forgotCheckout = DB::table('workings')->whereNull('deleted_at')->get();
            foreach($forgotCheckout as $f){
                $user_id = [$f->user_id];
            }
            -- "code" --
        })->daily();
    }
  • 写回答

1条回答 默认 最新

  • duanraotun1674 2018-08-17 10:07
    关注
    //app/console/Kernel.php
    
    use Illuminate\Support\Facades\Mail; //for use Mail facade
    
    protected function schedule(Schedule $schedule)
    {
        $forgot = [];
    
        $forgotCheckout = Working::whereNull('deleted_at')->get();
        foreach($forgotCheckout as $forgot){
               $forgot;
           }
    
        if(!is_null($forgot)){
            $schedule->call(function () use($forgotCheckout){
                Mail::send( //send email with valiable $forgot in View file.
                    'emails.forgot_checkout',
                    compact('forgotCheckout'),
                    function ($message) {
                        $message->to('test@email.com');
                        $message->subject('This is test mail');
                    }
                   );
            })->daily()->when(function() use ($forgotCheckout){ //define how often do this job
                if(!is_null($forgot)){
                \Log::info(Daily check completed.); //write log file                
                return true; // when() will work when return is true.
                }
                else {
                return false; // when() not work because return is false.
                }
            );
        }
    }
    

    And you can make and modify to use your data with $forgot data.

    // view/emails/forgot_checkout.blade.php
    
    This is test mail for scheduled mail sending...
    @foreach($forgotCheckout as $forgot)
      {{$forgot->id}}
      {{$forgot->name}}
    @endforeach
    

    As most of you know, if you know how to do then it's not difficult:)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画