Show the contents of the web.php file please. (line 3 in particular)
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.
@Sinnbeck here are the contents sir:
Illuminate\Support\Facades\Route; Route::get('/', function () { return view('welcome'); });
@Ramsey555 the first line misses a "use":
use Illuminate\Support\Facades\Route;
@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 :
@Sinnbeck l want to achieve this https://ibb.co/R7nzT6b
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.
@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 just call
the route-file tells the framework to call welcome.blade.php if you call /
@Dunsti l am still getting the same error here is y full code
@Ramsey555 why keep saying here is the full code? Do you see it?
@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
@Dunsti l want to achieve this https://ibb.co/R7nzT6b
Replace
Illuminate\Support\Facades\Route
With
use Illuminate\Support\Facades\Route;
And make sure you run that command first.
composer install
@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 Where are you getting that error? in the browser?
@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
@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..
@Ramsey555 How do you run it?
@MohamedTammam Open a terminal (cmd or powershell) and run composer install from this directory E:\Xampp\htdocs\onelastdance
@Sinnbeck You are mistaken, I was asking him how does he run the web.php.
@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 l run the file by right clicking on it,then run with Chrome browser. My Ide is PhpStorm
@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
@MohamedTammam I have a feeling that composer is installed but composer install was never run..Sorry for adding your name by mistake. :)
@MohamedTammam having done that and running index.php ,l am getting the default Laravel 8 page screen of documentation,laracast,news etc
@Sinnbeck having run composer install,l am getting "Nothing to install, update or remove Generating optimized autoload files"
@Ramsey555 You got the default Laravel 8 page, congratulations.
What else do you want?
@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?
@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.
@MohamedTammam Thanks for this ,l just feel sad even a simple "welcome "string is giving me issues to print in laravel 8.
@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 :).
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?
@jlrdw yes that's what l am exactly saying
@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.
@automica wooow maybe that's why am struggling...since in raw Php one can easily run a file and it works please help
@automica l want to achieve this https://ibb.co/R7nzT6b
@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
@Sinnbeck l am getting this error: Uncaught Error: Class 'Route' not found in E:\Xampp\htdocs\onelastdance\routes\web.php here is what l want https://ibb.co/R7nzT6b
@Ramsey555 You just said it worked like 10 minutes ago??
@Sinnbeck that was the default laravel 8 page that appears...l want my own "welcome" string printed instead of the default laravel page
@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
@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
@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.
@Ramsey555 have you considered taking some of the free training on laracasts. @jeffreyway teaches step by step.
@jlrdw any link?
@Ramsey555 https://laracasts.com/series/laravel-8-from-scratch
Also search for the PHP practitioner series, he demonstrates building a basic MVC php system.
Please or to participate in this conversation.