Reputation: 21
TestController
public function index()
{
$data = Users::all();
return view('welcome', compact('data'));
}
Routes
Route::get('/', 'TestController@index');
How can i call that route in my controller? I want to return route from index of my controller not the view.
Upvotes: 2
Views: 3189
Reputation: 520
You can use
return redirect()->route('/');
ref: https://laravel.com/docs/5.1/responses#redirecting-named-routes
Upvotes: 0
Reputation: 163768
Use redirect to route:
return redirect()->route('mainpage');
And it's also a good idea to add a name to a root route:
Route::get('/', 'TestController@index')->name('mainpage');
Upvotes: 1