Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel Blade @yield variable scope

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

@extends('layout.content')

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

nonverbose.blade.php

@extends('layout.content')

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

content.blade.php

@extends('layout.app')

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

I have also tried @yield('user', ['user' => $user])

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

like image 1000
Votemike Avatar asked Jul 28 '15 15:07

Votemike


1 Answers

Did you have tried to use @include?

@include('user', ['user' => $user])
like image 170
Franco Avatar answered Sep 17 '22 15:09

Franco