一段时间后如何执行某些功能?

时间:2017-01-29 11:02:47

标签: laravel laravel-5 laravel-5.2

我有这个功能,用户可以拒绝其他用户。

line

现在我想要的是检查用户是否在7天后拒绝其他用户,如果它不打电话给其他功能。

 public function rejectPersonalUser($id){
        $user = PersonalUser::findOrFail($id);
        $user->approved = 0;
        $user->business_user_id = NULL;
        $user->save();

        return redirect()->back()->withFlashMessage('User has been rejected successfully!!');
   }

1 个答案:

答案 0 :(得分:1)

您可以使用Task Scheduling,如果您希望它在一段时间后运行。

您可以使用:

$schedule->call(function () {
    //your block of codes here..
})->weekly()->mondays()->at('13:00');

或者更具体地说,根据您的需要,您可以调用不注入任何参数的函数,并尝试从那里调用用户。

$schedule->call(function () {
 //call someScheduleTaskForUser() from here.
})->weekly()->mondays()->at('13:00');


public function someScheduleTaskForUser() {
  //call  the setUser() function from here...
}

// This function could reside somewhere.
 public function setUser($id){
    $user = PersonalUser::findOrFail($id);
     if($user->approved == 0 && $user->business_user_id != NULL){
        $user->approved = 0;
        $user->business_user_id = NULL;
        $user->save();
    }
 }