'redirect back to previous page after log out in laravel 8

i want my app to be able to redirect back to the previous page after a user logs out.i have figured out redirecting back to previous page on sign up and log in.what i want to achieve is to be able to redirect back to previous page on log out.how can i achieve this.i have tried some methods i have researched here but none of them works. i tried this one but it didnt work.i created this function in the login controller

 public function getLogout()
{
    Auth::logout();

    return redirect()->back();
}


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source