下面是我的 View 和 Controller ,我希望 $name 变量可以在包含在主视图中的导航栏 View 中访问。有人知道解决方案吗?
userController.php
public function index($var){
$u_array = $var;
$name = $u_array->name;
return view('index',compact(name));
}
master.blade.php
@include('navbar')
<section class="main-container">
@yield('content')
</section>
index.blade.php
@extends('master')
@section('content')
<h2>{{$name}}</h2>
@endsection
navbar.blade.php
<h1>{{$name}}</h1>
最佳答案
将变量传递给 master.blade 然后 navbar.blade:
@extends('master', ['name' => $name]) //compact('name')
然后:
@include('navbar', ['name' => $name]) //compact('name')
关于php - 拉维尔 5.2 : How to get a variable in a subView of a parentView from another subView?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38124846/