Laravel #extends('layouts.app') not working on some pages - php

#extends('layouts.app')
does not work on some of my web pages. it just shows the content without the layout. why is this happening?
I already tried making a new layout folder and calling it but still some pages still doesn't show the layout.
both show.blade.php and create.blade.php doesn't display the layout
it only shows like this
app.blade.php
this is the navbar.blade.php

Your CSS file maybe not loading properly.
change your app.blade.php file like below,
<link rel="stylesheet" href= "/css/app.css" >

you might what to try this:
<link rel="stylesheet" href="{{ asset('css/app.css') }}" />

In my case this fixed it (had to add public):
href="{{ asset('public/css/app.css')

If your style css not working on every page, try adding it with the asset helper;
This help me to solve exactly the same problem. You can find in Laravel Docs. ;
https://laravel.com/docs/8.x/helpers#method-asset

Related

Do using if else condition in using external css and js in the main layout is better in Laravel?

I'm just new to Laravel and Vuejs, I have this problem that my system loads very slow because of external css and js I used. I only have one layout where all of my external css and js are imported. Do using if else condition before the runtime is a good approach to prevent the loading of unused external css and js?
here is a sample code where these two external css only runs on a single page
#if($_SERVER['REQUEST_URI']==='/dashboard/inventory')
<link href="{{ url('css/authenticated.css?d='. $date) }} " id="styles" rel="stylesheet">
<link href="{{ url('css/template/style.css?d='. $date)}}" rel="stylesheet">
#endif
You may create a section
like the following in your view, for example:
first go to your main page and create section in page
#extends('layouts.master')
#section('styles')
<link href="{{ url('css/authenticated.css?d='. $date) }} " id="styles" rel="stylesheet">
<link href="{{ url('css/template/style.css?d='. $date)}}" rel="stylesheet">
#stop
Then also in your layout, #yield that, for example:
<!--Dynamic StyleSheets added from a view would be pasted here-->
#yield('styles')

How to use style.css files in laravel 5.4?

In my project that is developed in laravel, i am trying to use a style.css file using blade engine. but it's not working for me anybody have better idea let me know.
Here is my code sample
<link href="{{ asset('/css/style.css')}}" rel="stylesheet" type="text/css">
it's tag is not working but when i'm us following it's working.
<link href="{{ asset('public/css/style.css')}}" rel="stylesheet" type="text/css">
now i want to now best practices of adding css files and how to include other files. like i've file header.blade.php it hold all css file link now i want to include header.blade.php in home.blade.php file both file in view directory.
Placed your css file inside laravel_project/public/css folder and use the link it into your view like:
<link href="{{asset('css/style.css')}}" rel="stylesheet" type="text/css"/>
I think this will help you Thanks.
I think your style.css is stored in public/css directory thats why it allow second you have provided.
And now your header.blade.php holds all your css files so you have to follow laravel's structure in layout if u have app.blade.php or any layout then its perfect otherwise you have to make it own
Sample app.blade.php (stored at views/layout/)
<!DOCTYPE html>
<html>
#include('layouts.partials.header') // path to your header.blade.php
#yield('content')
#include('layouts.partials.footer') // path to your footer.blade.php
</html>
Now this is your layout and you can use your layout and your header as well as footer in your view file like i am creating one blog_list.blade.php which is stored at views directory
blog_list.blade.php
#extends('layouts.app') // we are extending app.blade.php
#section('content')
// here whatever your content
#endsection
You can find more details on laravel's official site laravel-5.4
I hope it helps you. thank you.

How to override CSS in Laravel?

I'm making a website using Laravel and I'm happy with the standard CSS of it in the app.css file. However for one page I'd like to change the font size. Is there a way to import both the app.css and a customized CSS, so that the latter overrides the app.css? Or is there an easier way to do this? I want to change the style of text in tables, so I thought I had to use CSS for that. It's pretty much impossible to edit the app.css file because it's minimalized and I can't understand it.
Thanks in advance!
Put them in public folder and call it in the view with something like
<link href="{{ asset('css/mystyle.css') }}" rel="stylesheet">. Make sure You put it after <link href="{{ asset('css/app.css') }}" rel="stylesheet">
Create a new stylesheet in public/css/style.css
Include it into your blade template just like
<link href="{{ asset('css/style.css') }}" rel="stylesheet">

CSS doesn't work with long link in laravel

I have a interesting trouble, in my view I have:
<base href="{{asset('')}}" />
<link href="ad/bower_components/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet">
that my css's link , it was long but it still worked a month ago, but now it doesn't work, and I try :
<link href="{{ URL::asset('ad/bower_components/bootstrap/dist/css/bootstrap.min.css') }}" rel="stylesheet">
too, but it haven't worked yet,
but when I try a shorter link, it works normally, so why?
<link href="{{asset('link_to_css_file_in_public_folder')}}" rel="stylesheet" >
That should work.
Ps: put this code in your layouts->app.blade.php or any other layout you use.
in case you want to load separate css file in different pages in your layout call this #yield('styles') and then in your blade import your css file like my sample above inside
#section('styles')
your_code
#endsection
<link rel="stylesheet" href="{{URL::to('/')}}/asset/ad/bower_components/bootstrap/dist/css/bootstrap.min.css">
is your asset folder in public folder or not?..if it then it works

Laravel 5 Routing to CSS folder issue

I have the following route which loads the page but the css of the page doesn't loads.
Route::get('admins', function () {
return view('admins/index');
});
In the contrast the following route loads the same page but here I added index and the page loads correctly. but I also adds index with admins in the browser address bar.
Route::get('admins/index', function () {
return view('admins/index');
});
I am calling css files in the views like:
<link href="../assets/css/animate.min.css" rel="stylesheet" />
I searched for the solutions but didn't got anything.
For Laravel 4 & 5:
<link rel="stylesheet" href="{{ URL::asset('assets/css/animate.min.css') }}">
URL::asset will link to your project/public/ folder, so chuck your scripts in there.
Note: You'll need to be using blade templates to use this. All Blade templates should use the .blade.php extension.
i am using code like below for css and js :
<link rel="stylesheet" href="{{ asset('/') }}css/menu-style.css">
And css directory is in my "project/public" directory.

Categories