I've just installed a Laravel 5 project on MAMP and my pages are not finding the css files.
This is the link to my css in my app.blade.php file:
<link href="/css/app.css" rel="stylesheet">
And my .htaccess file has this line:
RewriteBase /laravel-site/laravel-5-app/public/
In the config folder my app.php file contains this:
'url' => 'http://localhost:8888/laravel-site/laravel-5-app/public/',
But when I open up this page: http://localhost:8888/laravel-site/laravel-5-app/public/auth/login and check the developer tools, it is looking for the css file at this location: http://localhost:8888/css/app.css
Just as a side note, if I go to this url: http://localhost:8888/laravel-site/laravel-5-app/public/ I get the correct welcome page.
You can use one of the following options:
<link href="{{ asset('css/app.css') }}" rel="stylesheet" type="text/css" >
<link href="{{ URL::asset('css/app.css') }}" rel="stylesheet" type="text/css" >
{!! Html::style( asset('css/app.css')) !!}
Here is the solution
{!! Html::style('css/select2.min.css') !!}
{!! Html::script('js/select2.min.js') !!}
<link rel="stylesheet" href="/css/bootstrap.min.css">
if you are using laravel 5 or 6 you should create folder css and call it with
it works for me
This works for me
If you migrated .htaccess file from public directory to project folder and altered server.php to index.php in project folder then this should works for you.
<link rel="stylesheet" href="{{ asset('public/css/app.css') }}" type="text/css">
Thanks
If you are using laravel
5 or 6:
<link rel="stylesheet" href="/css/bootstrap.min.css">
<link src="/images/test.png">
<!-- / is important and dont write public folder-->
_x000D_
In the root path create a .htaccess file with
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/public/
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /public/$1
#RewriteRule ^ index.php [L]
RewriteRule ^(/)?$ public/index.php [L]
</IfModule>
In public directory create a .htaccess file
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
if you have done any changes in public/index.php file correct them with the right path then your site will be live.
what will solve with this?
To fast apply simple regex.
search : href="(.+?)"
replace : href="{{ asset('$1') }}"
and
search : src="(.+?)"
replace : src="{{ asset('$1') }}"
I was having the same problem, until just now.
Removing the /
from before /css/app.css
so that its css.app.css
worked for me.
Stop artisan serve
and try using
php -S localhost:8000 -t public
You can simply create assets in public and added more paths and call in your head html the following code
Laravel version 6.0.2
I also had the same problem. I used
<link href="{{ asset('css/app.css') }}" rel="stylesheet" type="text/css" >
<link href="{{ asset('css/bootstrap.css') }}" rel="stylesheet">
And after moving the CSS folder from folder resource to folder public it works
Simply you can put a back slash in front of your css link
my opinion is that:
<link rel="stylesheet" href="{{ URL::to('/css/app.css') }}">
is the best method to route to your css files.
The URL::to()
also works for js
if you are on ubuntu u can try these commands:
sudo apt install npm
npm install && npm run dev
I used:
"{{asset('css/custom.css')}}"
"{{asset('css/app.css') }}"
First one is my own file the second one came with laravel. I'm using version 5.
http://spanibox.com/css/app.css works but http://spanibox.com/css/custom.css does not. I find this very weird.
It's works. For css:
<link href="css/app.css" rel="stylesheet">
Try to:
<link href="public/css/app.css" rel="stylesheet">
This worked for me:
If it's a css file tap
<link href="{{ asset('css/app.css') }}" rel="stylesheet" type="text/css" >
If it's an image tap
<link href="{{ asset('css/img/logo.png') }}" rel="stylesheet" type="text/css" >
Source: Stackoverflow.com