I have several routes in web.php:
Route::get('/','PagesController@index');
Route::get('/contact','PagesController@contact');
and so on...
I need to get in my PagesController the current 'module' (index, contact or smth else).
The Controller's code:
class PagesController extends Controller
{
public function index()
{
$menu = new Menu();
$links = $menu->getMenu();
//$header=url()->current(); // returns the full url, e.g. http://test.com/
//$header=Route::current(); // error: Class Route not found
return view("index",['links'=>$links,'header'=>$header]);
}
}
For example, $header should be equal to "/" inside PagesController@index
and $header = "contact"
inside PagesController@contact
.
I need the universal solution for all the modules I'll have in future.
Thanks a lot!