Laravel won't link stylesheet - php

I'm using Laravel 5.2.
I have public/app.css and i link it from views/layouts/app.blade.php with:
<link rel="stylesheet" href="{{ public_path('app.css') }}">
I have tried every combination that i can think of, like using asset() asset_path(), putting app.css in views/layouts/ with the app.blade.php file and nothing will work.
If I inspect the source of a page, it shows the link and the path is correct, but the styles won't apply.

Try this:
<link href="{!! asset('css/app.css') !!}" rel="stylesheet" type="text/css">

Try to use asset() method:
<link rel="stylesheet" href="{{ asset('app.css') }}">

Related

Laravel is not attaching css, but it is existing

I'm new in Laravel. I started new project with Jetstream, and all goes well excepting one thing: CSS file is empty so auth form is looking rawly.
I got public/css/app.css file with needed style code, but for some reason browser receives it as empty
In layout/app.blade.php is declared:
<link rel="stylesheet" href="{{ mix('css/app.css') }}">
I tried to replace it by:
<link rel="stylesheet" href="{{ asset('css/app.css') }}">
But it is not working. Any ideas? Thank you

Laravel 8 is not loading css and js

I have css under App/resources/css by default
when I open Login and Register page css is not loading. This is default css and js link on my app.blade.php
<script src="{{ asset('js/app.js') }}" defer></script>
<link href="{{ asset('css/app.css') }}" rel="stylesheet">
I did this
<link href="{{ URL::asset('assets/css/a.css') }}" rel="stylesheet">
and also tried
<script src="{{ asset('resources/js/app.js') }}" defer></script>
<link href="{{ asset('resources/css/app.css') }}" rel="stylesheet">
What shall I do to make it work.??
Move all your CSS and JavaScript to the public folder so that your structure becomes something like
public/
|--- css/
|---js/
Now to use your CSS and JavaScript from your new location do something like
<script src="{{ asset('js/app.js') }}" defer></script>
<link href="{{ asset('css/app.css') }}" rel="stylesheet">
This works because the asset() blade helper already looks from the public directory so you start your CSS and JavaScript URL construction from that point on
I would recommend to always use the mix helper in Blade like this
<script src="{{ mix('/js/app.js') }}"></script>
as it additionally properly takes care of versioned assets. Please make sure you either ran npm run dev or npm run prod (see Compiling assets) to generate the public/css/app.css and public/js/app.js files from the ones located in resources.

Route view don't load CSS Laravel

The CSS don't load em some routes, example, a route with a var:
//LINK
Route::get('/link/{id}', 'PagesController#link');
TEMPLATE:
<link rel="stylesheet" href="../public/css/style.css">,
How I can fix it?
To generate URL's for assets like CSS/JS/images/etc., in Laravel, use the helper function asset, instead of specifying the relative URL:
<link rel="stylesheet" href="{{ asset('css/style.css') }}">
See the documentation
<link rel="stylesheet" href="{{ asset('public/css/style.css') }} ">
or
<link rel="stylesheet" href="{{ asset('css/style.css') }} ">
Use absolute paths like this (starting from the end of 'public'):
<link rel="stylesheet" href="/css/style.css">,
The right solution is the following one:
<link rel="stylesheet" href="/css/style.css">
Don't forget to add the / before the css/style.css or it wont load.

Can't load CSS in Laravel

Hi I am currently learning Laravel and seem to be having issues loading custom CSS that is located in the public/css/bootstrap.css.
I have been attempting to load it via
<link href="{{ asset('css/bootstrap.css') }}" rel="stylesheet" type="text/css" >
But it is if the CSS is not getting picked up. When I view the page source (http://portfollo.co.uk/css/bootstrap.css) I just get an error. Any ideas ?
Try with public/css/bootstrap.css
<link href="{{ asset('public/css/bootstrap.css') }}" rel="stylesheet" type="text/css" >
OR
<link href="'/css/bootstrap.css'" rel="stylesheet" type="text/css" >
You should put your css file inside public folder, (app/public):
then in your head:
<link rel="stylesheet" href="{{ url('/') }}/style.css" type="text/css"/>
Public folder will contain all css and js files, you can also create assets folder inside public folder and then point to correct path:
<link rel="stylesheet" href="{{ url('/') }}/assets/css/style.css" type="text/css"/>
change name as public/css/bootstrap.css and put css in that folder. and give the same path.
This is not a CSS error. its Routing error. check your route.php file just check your source code like this view-source:http://portfollo.co.uk/css/bootstrap.css
you are trying something wrong ??

Stylesheets not loading on certain pages

i am using master pages in my application and all custom styling and bootstrap files are included there and its working fine but when i use wildcard for example localhost/final/User/id all bootstrap and custom styling links could not work, all files are in public folder
<!-- Bootstrap CSS -->
<link href="css/bootstrap.css" rel="stylesheet">
<link href="css/font-awesome.min.css" rel="stylesheet">
<link href="css/portal-style.css" rel="stylesheet">
<link href="css/portal-stylesheet.css" rel="stylesheet">
this is screen shot for my view with wildcard
this is link for all files that is not working when i use any wildcard
You should use asset() helper to build links to CSS:
<link href="{{ asset('css/bootstrap.css') }}" rel="stylesheet">
It'll work for you if you're keeping css files in public/css directory.
The reason this is happening is because of the way you have coded the path to the css file which is relative to the page you are viewing.
So when you view: localhost/final/user/id the browser is going to look for the css file here: localhost/final/user/css/bootstrap.css
Laravel has some helper methods to remove the pain of setting up your asset files (css, images, etc).
If you are using blade, you can use the asset() method like this:
<link href="{{ asset('css/bootstrap.css') }}" rel="stylesheet">
<link href="{{ asset('css/font-awesome.min.css') }}" rel="stylesheet">
<link href="{{ asset('css/portal-style.css') }}" rel="stylesheet">
<link href="{{ asset('css/portal-stylesheet.css') }}" rel="stylesheet">
Normally You can use asset() or secure_asset() for HTTPS, both will work when your assets, like css or js files are in public folder.
Or if you are not using public folder. Than url() will be there for you.
<link href="{{ asset('css/bootstrap.css') }}" rel="stylesheet">
OR
<link href="{{ url('public/css/bootstrap.css') }}" rel="stylesheet">

Categories