Non-static method Illuminate\Http\Request::url() cannot be called statically

I’m using Laravel 9 and I want to redirect user to same page url, so I tried this:

if(!$status){
    alert()->error('Wrong code!');
    return redirect(Request::url());
}

And I have included as well the Request but don’t know why get this error:

Non-static method Illuminate\Http\Request::url() cannot be called statically

So what’s going wrong here? How can I solve this issue?

>Solution :

You can use

return redirect()->back()->withInput();

Or

use Illuminate\Http\Request;

public function yourMethod(Request $request) # inject $request here
{
    return redirect($request->url());
}

Leave a Reply