I am developing a small web app using Laravel 5.6.
I recently upgraded Laravel to 5.6 and therefore also updated PHP to version 7.2.3 as php7.1 is a requirement for Laravel.
I am developing on a Windows 10 machine.
For testing I am using the php built-in webserver.
I either use the Laravel shortcut to start the server php artisan serve or I call directly the php -S localhost:8000 -t public command, the result is the same.
Since I updated php, I am not able to access any asset (css, js) through the browser.
blade file:
<head>
<meta charset="UTF-8">
<title>My Site</title>
<link href="{{ asset('css/search.css') }}" rel='stylesheet'>
</head>
Output in Chrome:
<head>
<meta charset="UTF-8">
<title>My Site</title>
<link href="http://localhost:8000/css/search.css" rel='stylesheet'>
</head>
Folder structure of the laravel project is:
- Root of Laravel Project
- public
- css
- search.css
I can't access the search.css file by entering http://localhost:8000/css/search.css, the server logs 127.0.0.1:52980 [404]: /css/search.css - No such file or directory
The file is in the right place, and the generated urls are also correct. In fact I didn't change anything and with older php version it worked. But of coursed I double checked a dozent times.
Validating the path in my controller.php with a few lines of code:
public function index(Request $request)
{
$t3 = public_path("css\\search.css");
var_dump($t3);
var_dump(file_exists($t3));
}
And the result was:
string(91) "C:\Users\me\Documents\LaravelProject\public\css\search.css" bool(true)
Deploying the application to a AWS EB environment will work.
So my guess, that there is a problem with the built-in webserver.
Can anybody imagine, what is wrong?
The small webserver is of course very handy during development.
Related
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
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.
I have my Laravel project that is hosted on a server, I made a copy of that project for testing and development on my local pc, but there is a difference that I don't know how to solve. On my local pc I do not need to specify public folder to access css files and other stuff, but on my server I have to specify, otherwise I doesn't find those files in public folder.
Example code on server:
<link rel="stylesheet" href="/public/css/main.css">
And on my local pc
<link rel="stylesheet" href="/css/main.css">
So I would love to make this thing the same on my local project, because now everytime I push changes to the server I need to add public to all the stuff and that's annoying. If I understand correctly it is done for security purposes, but I don't know how to make it on my project.
Use Laravel asset() function like below,
<link rel="stylesheet" href="{{asset('css/main.css')}}">
How do I put my Unity game built in WebGL into Laravel?
FYI, Unity WebGL, when built gives me these files:
- Build (folder)
- TemplateData (folder)
- index.html
Let me tell what I have done:
[ How I test if the game works in WebGL using XAMPP ]
I built a Unity game in WebGL
I put the built folder in xampp/htdocs directory
I run xampp, then turn on apache server
I open my browser and went to localhost/mygamefolder
It works fine, but this is using xampp
Now what I want is, how to test if the game works using server hosted using Laravel framework...
[ What I did ]
I put the built folder into mylaravelproject/public directory
I copied the content of index.html file from the Unity built project and paste it in one of my views file (.blade.php).
I changed the stylesheet and references at the tag according to the path where I put the built folder is.
I open the terminal and run 'php artisan serve'
I open browser and go to the IP address as shown in the terminal
I went to the page where I put the game, but the game does not load. (Game only, other thing like navbar and button I put etc works fine)
I open console, it said:
"Uncaught ReferenceError: UnityLoader is not defined
"Failed to load resource: the server responded with a status of 404 (Not Found)" at demo:15"
Any ideas? Or if you can direct me to tutorial on how to put your Unity WebGL game into Laravel that would be good. Since I tried to search for it and so far I found nobody is putting Unity in their Laravel website.
--- Edit: Here is the index.html file as produced by Unity WebGL ---
<!DOCTYPE html>
<html lang="en-us">
<head>
<meta charset="utf-8">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Unity WebGL Player | Projectile</title>
<link rel="shortcut icon" href="TemplateData/favicon.ico">
<link rel="stylesheet" href="TemplateData/style.css">
<script src="TemplateData/UnityProgress.js"></script>
<script src="Build/UnityLoader.js"></script>
<script>
var gameInstance = UnityLoader.instantiate("gameContainer", "Build/OrangeCodeGame.json", {onProgress: UnityProgress});
</script>
</head>
<body>
<div class="webgl-content">
<div id="gameContainer" style="width: 960px; height: 600px"></div>
<div class="footer">
<div class="webgl-logo"></div>
<div class="fullscreen" onclick="gameInstance.SetFullscreen(1)"></div>
<div class="title">Projectile</div>
</div>
</div>
</body>
</html>
Figured it out:
When you build Unity game with WebGL, Unity will provide this files:
index.html
Build (folder)
TemplateData (folder)
Copy the index.html into the resources/views folder and change the extension of "index.html" into "index.blade.php"
Open public folder in the Laravel project, copy and paste the Build and TemplateData folder.
Go to routes/web.php, add the controller that will route to the index.blade.php.
4. You can test it with button or anything you like.
Done, now it will works fine. You can even put Laravel content inside the index.blade.php of unity with your navbar or anything you like.
Plus, the authentication session can also be passed normally.
I am trying to upload a laravel project to cpanel hosting server. My laravel version is 5.3 and php version on the server is 5.6.
What I have done is:
Create a folder called "online_system" to root of file manager.
Copy contents of laravel project except public folder.
Create a folder called "online_system" to public_html.
Copy contents of public folder of laravel project.
Jump to index.php file.
Edit require __DIR__.'/../../online_system/bootstrap/autoload.php';
Edit $app = require_once __DIR__.'/../../online_system/bootstrap/app.php';
Change .env to link DB.
Open domain/online_system.
Home page is working fine, but as long as I click login or register provided by laravel, then the website looks plain without css load.
How can I solve this problem?
Give it a try
<link rel="stylesheet" type="text/css" href="{{ url('online_system/css/styl.css') }}" />
I guess this will do the trick:
<link rel="stylesheet" type="text/css" href="/public/css/style.css"/>
If your project is on the server and change your views, So clear view cache:
php /path_to_your_project/ artisan view:clear
i have installed Laravel 5.4 in localhost. I'm using XAMPP to host the application. I'm using Laravel's inbuilt Blade template structure to show the data. I have used asset() helper to load my assets files which is inside the public folder. A sample code is here.
<link href="{{URL::asset('backend/vendors/bootstrap/dist/css/bootstrap.min.css')}}" rel="stylesheet" type="text/css">
But CSS file is not loading. I discovered this from Chrome developer tool's Network section. I have worked with Laravel before with it's other version and this is the first time that i'm working with version 5.4. Hope someone will assist me to solve this.
you can use only asset function like this i hope you have css folder inside public folder as mentioned in the path.
<link href="{{asset('backend/vendors/bootstrap/dist/css/bootstrap.min.css')}}" rel="stylesheet" type="text/css">
asset()
Generate a URL for an asset using the current scheme of the request (HTTP or HTTPS):
Ref: https://laravel.com/docs/5.4/helpers