gpt4 book ai didi

php - 拉维尔 5.2 : How to get a variable in a subView of a parentView from another subView?

转载 作者:可可西里 更新时间:2023-11-01 00:40:55 25 4
gpt4 key购买 nike

下面是我的 View 和 Controller ,我希望 $name 变量可以在包含在主视图中的导航栏 View 中访问。有人知道解决方案吗?

userController.php

public function index($var){
$u_array = $var;
$name = $u_array->name;
return view('index',compact(name));
}

ma​​ster.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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com