Blessan Kurien
Blessan Kurien

Reputation: 1665

Laravel 5.3 :class Http\Controllers\Route' not found

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

Answers (4)

Ercan Koca
Ercan Koca

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

Prem Sagar
Prem Sagar

Reputation: 165

To use Route::current(), you have to include Route class in your controller:

use Route;

Upvotes: 1

Mayank Pandeyz
Mayank Pandeyz

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

Kishan Dalsania
Kishan Dalsania

Reputation: 95

use Illuminate\Routing\Controller;

Use these code in the below of your controller and try it.

Upvotes: 2

Related Questions