Master layout (ok)

<?php
namespace App\Http\Controllers;
use App\Product;
use Illuminate\Http\Request;

class Test extends Controller {
  /**
   * Display a listing of the resource.
   *
   * @return \Illuminate\Http\Response
   */
  public function index() {
    return view('child');
  }
}
<?php

use Illuminate\Support\Facades\Route;

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/

Route::get('/', function () {
    return view('welcome');
});
Route::resource('products','ProductController');
Route::resource('test','Test');

Dữ liệu cố định:

@yield từ khóa giữ chỗ cố định.

<!-- Stored in resources/views/layouts/app.blade.php -->
<html>
    <head>
        <title>App Name - @yield('title')</title>
    </head>
    <body>
        @section('sidebar')
            This is the master sidebar.
        @show
        <div class="container">
            @yield('content')
        </div>
    </body>
</html>

Dữ liệu thay đổi @section && @show dùng mở rộng

@section Lệnh này cũng chấp nhận một giá trị mặc định là tham số thứ hai của nó. Giá trị này sẽ được hiển thị nếu phần được mang lại không được xác định:@yield

<!-- Stored in resources/views/layouts/app.blade.php -->
<html>
    <head>
        <title>App Name - @yield('title')</title>
    </head>
    <body>
        @section('sidebar')
            This is the master sidebar.
        @show
        <div class="container">
            @yield('content')
        </div>
    </body>
</html>
@extends('layouts.app')

@section('title', 'Page Title')

@section('sidebar')
  @parent
  <p>This is appended to the master sidebar.</p>
@endsection

@section('content')
  <p>This is my body content.</p>
@endsection

Last updated