laravel实践8.内嵌页面

1.编辑被嵌入的页面

resources/views/shared/_info.blade.php

<a href="{{ route('users.show', $user->id) }}">
  <img src="{{ $user->buildImage() }}" alt="{{ $user->name }}" class="img"/>
</a>
<h1>{{ $user->name }}</h1>
<p>{{$user->intro}}</p>

2.主页面嵌入

resources/views/users/show.blade.php

@extends('layouts.default')
@section('title', $user->name)

@section('content')
<div class="row">
  <div class="offset-md-2 col-md-8">
    <div class="col-md-12">
      <div class="offset-md-2 col-md-8">
        <section class="user_info">
          @include('shared._info', ['user' => $user])
        </section>
      </div>
    </div>
  </div>
</div>
@stop

可以通过给 @include 方法传参,将用户数据以关联数组的形式传送到 _info 局部视图上。

@include('shared._info', ['user' => $user])

 

posted @ 2019-12-27 17:23  GIC扫地僧  阅读(402)  评论(0编辑  收藏  举报