Reputation: 925
I have this function where user can reject other user.
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!!');
}
Now what i want is to check if user reject other user after 7 days if its not to call other function.
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();
}
}
Upvotes: 2
Views: 3105
Reputation: 4974
You can use Task Scheduling, If you want it to run after some time period.
You could just use like:
$schedule->call(function () {
//your block of codes here..
})->weekly()->mondays()->at('13:00');
Or more specifically for your needs you could call to a function that doesn't inject any parameters and try to call the user from there.
$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();
}
}
Upvotes: 3