laravel - .Blade.php page doesn't work with localhost but with php artisan server it's work
Hey guys am new to laravel and when i create route veiw to .blade.php page it's doesn't work with apache2 localhost even with virtual host but if i run php artisan server
it works fine.
Here's My code :
In web.php file in routes directory:
Route::get('users', function(){
return view('users');});
In resources/view i have users.blade.php it contain:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Users</title>
</head>
<body>
<h1>Welcome From Users View</h1>
</body>
</html>
Now if I open localhost/project/public it will work and show me laravel default page.
But if I run localhost/project/public/users it won't work.
But When i type in terminal php artisan ser
and go to 127.0.0.1:8080 'as he told me then' /users it will work just fine and show me the content of users.blade.php
Some info about the enviroment :
Linux Mint 21 Cinnamon 5.4.12
and Apache2 local server without xampp or lampp
All the extentions are installed
Answer
Solution:
Your localhost server is entirely different from that provided by php artisan serve
If you are using xampp/wamp or any other related software, you cant access the urls that way.
Using the php artisan serve
, your base url is 127.0.0.1:8000
In your web.php this code that you wrote:
Route::get('users', function(){
return view('users');});
It means that if you access the url 127.0.0.1:8080/users
it will display the view file called users.blade.php
Take a look at the docs
With that said. You should not access it via the localhost url.
Source