Laravel View

laravel

Where should we keeps our views?

resources -> views

How can we create a layout?

  1. Create a folder name layouts inside the resources->views folder
  2. Create a file name master.blade.php inside the layouts folder
<html>
  <head>
    <title>@yield(‘title’)</title>
  </head>
  <body>
    <div class=“container-fluid”>
      @yield(‘content’);
    </div>
  </body>
</html>

The @ sign signifies a Blade expression.

How can a view inherit from a layout?

Use the @extend construct like:

@extend('layouts.master')

In the above code, 'layouts' is the name of the folder that contains the layouts, and master is the name of the file containing the layout. Notice that we are not using the full name of the file here.

How can a layout include a normal php file?

@include('includes.header')
<!DOCTYPE html>
<html>
<head>
    <title>@yield('title')</title>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
    <link rel="stylesheet" href="{{ URL::to('src/css/main.css') }}">
</head>
<body>
    @include('includes.header')
    <div class="container">
        @yield('content')
    </div>

    <script src="//code.jquery.com/jquery-1.12.0.min.js"></script>
    <script src="//code.jquery.com/jquery-migrate-1.2.1.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script>
    <script src="{{ URL::to('src/js/app.js') }}"></script>
</body>
</html>

How can a view target a particular section of a layout?

@extend('layout.master')

@section('title')
  Welcome;
@endsection

@section('content')
@endsection

How can we implement a single page application using Laravel?

This is very easy. There is nothing limiting us from doing this. Create a default view that are empty, and then use Angular or whatever JS library on the front-end. For pages that need server-side rendering, we can use different views / layout.

What is the template engine used by Laravel?

Blade.

How can we use a route inside our view?

<form action="{{ route('signup') }}" method="post">
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License