注意到Laravel 5中扩展视图的奇怪行为。这似乎是Laravel中的一个错误,我准备了简单的代码,因此您可以轻松地重现它:
控制器:
$items = [
['id' => 1],
['id' => 2],
];
return view('list', [
'items' => $items
]);
list.blade.php:
@foreach ($items as $item)
@include('single-extended', $item)
@endforeach
single.blade.php:
<div>id: {{ $id }}</div>
@yield('block')
单extended.blade.php:
@extends('single')
@section('block')
<div>id in extended: {{ $id }}</div>
@endsection
当前输出:
id: 1
id in extended: 1
id: 2
id in extended: 1
预期产出:
id: 1
id in extended: 1
id: 2
id in extended: 2
这是一个错误还是我做错了什么?