How to Include External CSS and Js File in Laravel 5

Including external css and JS files in Laravel 5

All assets must be in public folder where your app root directory. https://laravel.com/docs/7.x/structure#the-public-directory

adding css and js file in laravel 5.3

Crate header.blade.php

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="csrf-token" content="{{ csrf_token() }}" />
<meta name="description" content="">
<meta name="author" content="">

<title>dhinchakwale</title>
<!-- Bootstrap Core CSS -->
<link href="{{ asset('/css/bootstrap.min.css') }}" rel="stylesheet">

<link href="{{ asset('/css/datepicker.css') }}" rel="stylesheet" type="text/css">
<link href="{{ asset('/css/bootstrap-timepicker.min.css') }}" rel="stylesheet" type="text/css">

<link href="{{ asset('/css/dataTables.bootstrap.css') }}" rel="stylesheet">
<!-- Custom CSS -->
<link href="{{ asset('/css/admin.css') }}" rel="stylesheet">

<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
<script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->

<!-- jQuery -->
<script src="{{ asset('/js/jquery.min.js') }}"></script>
</head>

<body id="page-top">
<nav class="navbar navbar-default">
<div class="container-fluid">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="/"><img alt="Brand" src="{{asset('/images/logo.png')}}" class="img-brand"></a>
</div>
</div>
</nav>
<div class="content-div">
@yield('content')
</div>
<div class="clearfix"></div>

<!-- Bootstrap Core JavaScript -->
<script src="{{ asset('/js/bootstrap.min.js') }}"></script>
<script src="{{ asset('/js/bootstrap-datepicker.js') }}"></script>
<script src="{{ asset('/js/bootstrap-timepicker.min.js') }}"></script>
</body>
</html>

And use like this
First extends header
Second Section of your content

@extends('layouts.header')
@section('content')
<section class="content-header">
<h1>
Hello
</h1>
</section>
@stop

How to link external CSS and Script (assets) in Laravel 5.1 project

Thanks guys for a help I did solve my problem.

  1. I went again at http://laravel.com/docs/5.1/helpers#method-asset
    • there I found they say $url = asset('img/photo.jpg'); will give me the url to my asset file.
  2. So I Route...

    Route::get('check', function () {

    $url = asset('assets/css/headers/header-default.css');

    return $url;
    });

    I got the link http://localhost/Dentist/public/assets/css/headers/header-default.css

  3. So i just violate the rule if there was any and I did this in my stylesheet.

<link rel="stylesheet" href="<?php echo $url = asset('assets/css/style.css'); ?>">

--> ** Apart from that you can do this **

{!!asset('assets/plugins/jquery/jquery.min.js')!!}

because as the said if you use blade, then there is no need of using <?php echo ; ?> command... so I replaced <?php echo $url = ; ?> with {!! asset('assets/css/...') !!}
Make sure your files are in public/assets/ directory

Thanks all



Related Topics



Leave a reply



Submit