Reputation: 1665
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.
Upvotes: 1
Views: 13047
Reputation: 11
You're getting this error because the Route
facade isn't imported inside your code. You need to import it by using the following statement:
use Illuminate\Support\Facades\Route;
Upvotes: 1
Reputation: 165
To use Route::current(), you have to include Route class in your controller:
use Route;
Upvotes: 1
Reputation: 26288
To use Route::current(), you have to use Route like:
use Illuminate\Routing\Route;
Note:
Look at your app.php
, you should have this on 'aliases'
array:
'Route' => "Illuminate\Support\Facades\Route",
Upvotes: 9
Reputation: 95
use Illuminate\Routing\Controller;
Use these code in the below of your controller and try it.
Upvotes: 2