Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Ramsey555's avatar

How can l get rid of this error

l am getting this error Fatal error: Uncaught Error: Undefined constant 'Illuminate\Support\Facades\Route' in E:\Xampp\htdocs\onelastdance\routes\web.php:3 whenever l am trying to run my web.php under the routes folder . Kindly help.

0 likes
46 replies
Sinnbeck's avatar

Show the contents of the web.php file please. (line 3 in particular)

1 like
Ramsey555's avatar

@Sinnbeck here are the contents sir:

Illuminate\Support\Facades\Route; Route::get('/', function () { return view('welcome'); });

Dunsti's avatar

@Ramsey555 the first line misses a "use":

use Illuminate\Support\Facades\Route;

1 like
Ramsey555's avatar

@Dunsti after adding the "use" l am getting Fatal error: Uncaught Error: Class 'Illuminate\Support\Facades\Route' not found in E:\Xampp\htdocs\onelastdance\routes\web.php:17 Below is my code on web.php :

Dunsti's avatar

what exactly do you mean with "whenever l am trying to run my web.php under the routes folder" ???

this file is not meant to be run manually - see it more as a config-file that is run by the framework, when you call your URL in the browser.

1 like
Ramsey555's avatar

@Dunsti Essentially l am new to Laravel,,,,after successfully installing it,l want to run my views and change the string at return view('welcome'); to something like return view('Hi there'); so that l can see the changes when l run the project in the browser. Which particular file do l need to run so that l can see the "welcome" text that comes by default.

Ramsey555's avatar

@Snapey here it is <?php

/use Illuminate\Support\Facades\Route;/

//Illuminate\Support\Facades\Route;

Route::get('/', function () { return view('welcome'); });

l want to see the welcome text printed on the screen

MohamedTammam's avatar

Replace

Illuminate\Support\Facades\Route

With

use Illuminate\Support\Facades\Route;

And make sure you run that command first.

composer install
1 like
Ramsey555's avatar

@MohamedTammam l have already installed composer ...upon adding use as you have suggested l a getting an error that reads: Uncaught Error: Class 'Illuminate\Support\Facades\Route' not found in E:\Xampp\htdocs\onelastdance\routes\web.php:18

Ramsey555's avatar

@MohamedTammam Yes in the browser whenever l run the file web.php under the routes folder since l want to see the view "welcome" text printed on the screen

Sinnbeck's avatar

@Ramsey555 Does your project have folder called vendor? If not that means that you have succesfully run composer install

Beware.. composer install and "installing composer" are not the same..

1 like
Sinnbeck's avatar

@MohamedTammam Open a terminal (cmd or powershell) and run composer install from this directory E:\Xampp\htdocs\onelastdance

Ramsey555's avatar

@Sinnbeck Alright let me give it a try n see. l thought running my first text unto the browser won't be that demanding in Laravel

MohamedTammam's avatar

@Ramsey555 You are doing it wrong, you need to start with index.php. Try running the following command and open the URL that will appear in the browser.

php artisan serve
Sinnbeck's avatar

@MohamedTammam I have a feeling that composer is installed but composer install was never run..Sorry for adding your name by mistake. :)

Ramsey555's avatar

@MohamedTammam having done that and running index.php ,l am getting the default Laravel 8 page screen of documentation,laracast,news etc

Ramsey555's avatar

@Sinnbeck having run composer install,l am getting "Nothing to install, update or remove Generating optimized autoload files"

Ramsey555's avatar

@MohamedTammam l want something like "hello word" my own custom text. l am watching a tutorials and the tutor is writing strings in routes that are printed on the screen how can l achieve this?

MohamedTammam's avatar

@Ramsey555 In the routes you can return a string or a view if you want to more control.

String Example

Route::get('/', function(){
	// You can echo things here if you want to
	return 'Hello World';
});

View Example

Route::get('/', function(){
	return view('your_file'); // That will point to 'resources/views/your_file.blade.php'
});

PS: you should follow the tutorial and finish it then you will know what to do. That thing is very basic and easy if you know how the framework is working.

1 like
Ramsey555's avatar

@MohamedTammam Thanks for this ,l just feel sad even a simple "welcome "string is giving me issues to print in laravel 8.

MohamedTammam's avatar

@Ramsey555 Yeah it so simple, but simple for people who know the life cycle for Laravel. not for the new learners. We all have been there before.

Congratulations, you learned new thing today that you will almost keep using it for the rest of your life.

Happy learning :).

1 like
jlrdw's avatar

l run the file by right clicking on it,then run with Chrome browser.

@ramsey555 are you saying you right click on web.php and try to run it in browser?

1 like
automica's avatar

@Ramsey555 thats your problem then.

laravel sites need to be set up so that web_root is /public/index.php. You cant just open individual php files in your browser and expect them to work.

2 likes
Ramsey555's avatar

@automica wooow maybe that's why am struggling...since in raw Php one can easily run a file and it works please help

Sinnbeck's avatar

@Ramsey555 Replace this

return view('welcome'); //before
return 'welcome'; //after

view() loads the contents of the welcome.blade.php file in the resources/views directory

1 like
Ramsey555's avatar

@Sinnbeck that was the default laravel 8 page that appears...l want my own "welcome" string printed instead of the default laravel page

automica's avatar

@ramsey555 you need to stop hacking at your code and set up your development environment correctly.

There are a number of ways you can host laravel locally.

  • using docker / sail
  • Apache virtualhosts
  • Laravel's artisan:serve command
  • php's built in server
  • MAMP/ WAMP / XAMP

you won't get anywhere just trying to execute php files individually from your IDE.

Read the documentation on how to start a project. https://laravel.com/docs/8.x/installation#your-first-laravel-project

if you want to use artisan serve, the following is helpful. https://gist.github.com/hootlex/da59b91c628a6688ceb1

1 like
Ramsey555's avatar

@automica Thanks l am just seeking help...l will go through your guide...l feel confused and frustrated even a simple hello world is giving me problems inlarvale yet in Php you can just create a file and run it

1 like
Snapey's avatar

@Ramsey555 Laravel IS php

But it uses a front-end router so that all routes go to index.php and the code there works out from web.php which resource you want to access.

Laravel is a complete framework. To get it to work, you must pass through its entry point.

2 likes

Please or to participate in this conversation.