Laravel Blade @yield变量范围 [英] Laravel Blade @yield variable scope

查看:168
本文介绍了Laravel Blade @yield变量范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个页面几乎相同.一个显示用户列表,另一个显示相同的列表,但包含更多详细信息. 所以我称两个扩展相同包装器的视图.但是,Laravel抱怨$ user没有在verbose.blade.php中定义.我正在将$ users传递到似乎可用于content.blade.php的视图,但是在foreach循环中创建的$ user似乎无法在verbose.blade.php中访问.

I have two pages that are almost identical. One shows a list of users, the other shows the same list, but with more verbose information. So I am calling two views that extend the same wrapper. However, Laravel complains that $user is not defined in verbose.blade.php. I am passing $users to the view which seems to be available to content.blade.php but the $user that is created within the foreach loop doesn't seem to be accessible in verbose.blade.php.

verbose.blade.php

verbose.blade.php

@extends('layout.content')

@section('user')
    {{ dd($user) }}
@endsection

nonverbose.blade.php

nonverbose.blade.php

@extends('layout.content')

@section('user')
    {{ dd($user) }}
@endsection

content.blade.php

content.blade.php

@extends('layout.app')

@section('content')
    @foreach($users as $user)
        @yield('user')
    @endforeach
@endsection

我也尝试过@yield('user', ['user' => $user])

我该如何使verbose.blade.php中的$ user可用?

How would I go about making $user available in verbose.blade.php?

推荐答案

您是否尝试过使用@include?

Did you have tried to use @include?

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

这篇关于Laravel Blade @yield变量范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆