简体   繁体   中英

when i am try to redirect to another page in laravel 5.6 then getting error like “Sorry, the page you are looking for could not be found.”

Thank In Advance for view my question

I am working on laravel 5.6 . i am making condition with if statement

like

if($value == 5){
   return redirect('Mycon/Home');
}else{
//some thing
}

i am also use use Illuminate\\Support\\Facades\\Redirect; on controller file. My condition work and also redirect to right url mean http://localhost/sample/test/Mycon/Home But After redirect url is right but error show like Sorry, the page you are looking for could not be found.

I am also add function in route file like Route::get('/Home', 'Mycon@Home');

If you registered the route:

Route::get('/Home', 'Mycon@Home');

You should redirect like this:

return redirect('Home');

First param is url, second is the action, if you want to do it by action you should redirect like this:

return redirect()->action('Mycon@Home);

Your route is not the same as the redirect route:

if($value == 5){
   return redirect('Mycon/Home');
}else{
//some thing
}

Route should be something like :

Route::get('/Mycon/Home', 'Mycon@Home');

I will suggest the below example:

Route :

Route::get('mycon/home', 'MyController@showHome')->name('home');

Redirect :

return redirect()->route('home');

Have fun :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM