I am trying to print the current route in my controller
namespace findetrip\Http\Controllers;
use Illuminate\Http\Request;
class HomeController extends Controller
{
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('auth');
}
/**
* Show the application dashboard.
*
* @return \Illuminate\Http\Response
*/
public function index($page = 'home')
{
echo $route = Route::current();
return view('admin.'.$page,['pageName'=>$page]);
}
}
But I got the following error:
Class 'findetrip\Http\Controllers\Route' not found
I found many questions similar to this issue, but didn't get a proper solution.
Routebut you have not included it in your namespace, so your script can't find it. Either use full url or include the namespace. PS: An IDE like PhpStorm will do this for you automatically.\Routeif you don't want to add use (it will use facade from alias), if you would call something dynamic on some Route instance, you would want to instead add useuse Illuminate\Routing\Route;