I have methods where i can soft delete
my model, restore
them and hard delete
(wipe from database) theme,
So far everything is ok, what I want in additional to that is to hard delete after 30 days
passed from soft delete
info, so in that way even if admin forget to hard delete models it will delete automatically after 30 days.
Here is my codes:
soft delete
public function destroy($id)
{
$user = User::findOrFail($id);
$user->delete();
Mail::to($user->email)->send(new adminsoftdeleteduser($user));
return redirect()->route('users.index')->with('success', 'User successfully deleted.');
}
restore
public function restore($id)
{
$user = User::onlyTrashed()->where('id', $id)->restore();
// Mail::to($user->email)->send(new adminrestoreduser($user));
return redirect()->route('users.index')->with('success', 'User successfully restored.');
}
hard delete
public function forcedelete($id)
{
$user = User::where('id', $id)->forcedelete();
Storage::delete($user->image);
return redirect()->route('users.index')->with('success', 'User Permanently deleted.');
}
Question
- what should i add to my
hard delete
function in order to delete my model after 30 days ofdeleted_at
column data?
Update
I've tried schedule way and as i cannot use cron job to test it so i used php artisan schedule:run
and here is the result I've got: