How can I redirect a route using laravel? -


i use group visualize project's routes.php, problem is

for example, when user access "/dir", want make redirected "/dir/ele"

route::group(['prefix' => 'dir'], function () {     route::group(['prefix' => 'ele'], function () {         route::controller('/', 'dir\elecontroller');     });     redirect::route('ele'); } 

why not working?

the route dir/ele going controller, doing redirect in routes.php instead of in controller.

you should use closure route , in routes.php or use controller , move redirect controller:

closure route in routes.php:

route::group(['prefix' => 'dir'], function () {     route::group(['prefix' => 'ele'], function () {         route::get('/', function() {             return redirect::to('ele');         });     }); }); 

which can simplified to:

route::group(['prefix' => 'dir'], function () {     route::get('ele', function(){         return redirect::to('ele');     }); }); 

or use controller way:

routes.php

route::group(['prefix' => 'dir'], function () {     route::group(['prefix' => 'ele'], function () {         route::controller('/', 'elecontroller@redirect');     }); } 

elecontroller.php

class elecontroller extends basecontroller {     function redirect() {         return redirect::to('ele');     } } 

Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -