Laravel @extends Not Working Properly When Trying To Reference Main Layout

- 1 answer

I have an issue with the @extends() function for Laravel. My views don't seem to extend the layout at all. I don't know how to fix this.

Here is the main layout file (it's located in views>layouts>app.blade.php):

   <!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <!-- CSRF Token -->
    <meta name="csrf-token" content="{{ csrf_token() }}">

    <title>{{ config('', 'Pet Me') }}</title>

    <!-- Scripts -->
    <script src="{{ asset('/js/app.js') }}" defer></script>

    <!-- Fonts -->
    <link rel="dns-prefetch" target="_blank" rel="nofollow noreferrer" href="//">
    <link target="_blank" rel="nofollow noreferrer" href="" rel="stylesheet">

    <!-- Styles -->
    <link target="_blank" rel="nofollow noreferrer" href="{{ asset('/css/app.css') }}" rel="stylesheet">

<div id="app">
    <nav class="navbar navbar-expand-md navbar-light bg-white shadow-sm">
        <div class="container">
            <a class="navbar-brand" target="_blank" rel="nofollow noreferrer" href="{{ url('/') }}">
                {{ config('', 'Pet Me') }}
            <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="{{ __('Toggle navigation') }}">
                <span class="navbar-toggler-icon"></span>

            <div class="collapse navbar-collapse" id="navbarSupportedContent">
                <!-- Left Side Of Navbar -->
                <ul class="navbar-nav mr-auto">


                <!-- Right Side Of Navbar -->
                <ul class="navbar-nav ml-auto">
                    <!-- Authentication Links -->
                        <li class="nav-item">
                            <a class="nav-link" target="_blank" rel="nofollow noreferrer" href="{{ route('login') }}">{{ __('Login') }}</a>
                        @if (Route::has('register'))
                            <li class="nav-item">
                                <a class="nav-link" target="_blank" rel="nofollow noreferrer" href="{{ route('register') }}">{{ __('Register') }}</a>
                        <li class="nav-item dropdown">
                            <a id="navbarDropdown" class="nav-link dropdown-toggle" target="_blank" rel="nofollow noreferrer" href="#" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" v-pre>
                                {{ Auth::user()->name }} <span class="caret"></span>

                            <div class="dropdown-menu dropdown-menu-right" aria-labelledby="navbarDropdown">
                                <a class="dropdown-item" target="_blank" rel="nofollow noreferrer" href="{{ route('logout') }}"
                                    {{ __('Logout') }}

                                <form id="logout-form" action="{{ route('logout') }}" method="POST" style="display: none;">

    @if ($errors->any())
                @foreach ($errors->all() as $error)

    @if (session('message'))
        <p><b>{{session ('message')}}</b></p>

    <main class="py-4">

and this is one of the views I am trying to have that extend app (located in views>home.blade.php):


<div class="container">
    <div class="row justify-content-center">
        <div class="col-md-8">
            <div class="card">
                <div class="card-header">Dashboard</div>

                <div class="card-body">
                    @if (session('status'))
                        <div class="alert alert-success" role="alert">
                            {{ session('status') }}

                    You are logged in!

It doesn't look appropriate at all.



Your code is extending the layout correctly as it shows the content of the <nav> and also the content from your home.blade.php file. It seems to me that your CSS is not loading correctly.

I recommend you check in the console that the app.css file is loading correctly. If not please make sure that the app.css file is present on the following path from your the root directory of your Laravel project-

public > css > app.css

Also, it would be more helpful if you could share the screenshot of your console.

Laravel initialises the project with app.css file, placed in the public/css directory. This file is noting but a minified version of Bootstrap's CSS file (docs). In case your file is deleted for some reason. THere is how you can get it -

OPTION 1 Using the CDN of bootstrap's css file.

To do this replace <link target="_blank" rel="nofollow noreferrer" href="{{ asset('/css/app.css') }}" rel="stylesheet"> with <link rel="stylesheet" target="_blank" rel="nofollow noreferrer" href="" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">. You can get the cdn from here.


  1. Download Bootstrap from here.
  2. Unzip the downloaded folder.
  3. Go to the css folder.
  4. Copy the bootstrap.min.css and paste in public/css folder in your Laravel project.
  5. Rename the pasted file to app.css.

Your css should load now.

One probable reason your app.css is maybe because you have executed the php artisan preset none command, which removes Laravel's default frontend scaffolding (docs).