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
Post a Comment