Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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());
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading