環境
Homestead
Laravel 9.11
現象
複数のbladeファイルを@includeしたときに、指定したものと異なるbladeが読み込まれてしまう。
php
1@include('hoge_list.section.section_a') 2@include('hoge_list.section.section_b')
こうした時に、section_bの欄に、section_aのbaldeがincludeされてしまいます。
→section_aが2回includeされる
前後を逆にした場合、section_bが2回includeされるため、bladeファイル自体に問題はないと考えており、
extendsやincludeの関係性に問題があるかと疑っていますが、解決できない状況です。
フォルダ構成
views ┣ hoge_list ┃ ┣ section ┃ ┃ ┣ section_a.blade.php ┃ ┃ ┗ section_b.blade.php ┃ ┗ main.blade.php ┗ template ┣ section.blade.php ┗ parent.blade.php
ソース
template\parent.blade.php
php
1<!DOCTYPE html> 2<html lang="ja"> 3<head> 4 ~省略~ 5</head> 6<body> 7 @yield('contents') 8</body> 9</html>
template\section.blade.php
~省略~
hoge_list\main.blade.php
php
1@extends('template.parent') 2 3@section('contents') 4 @include('hoge_list.section.section_a') 5 @include('hoge_list.section.section_b') 6@endsection
hoge_list\section\section_a.blade.php
php
1@extends('template.section') 2 ~省略~
routes\web.php
php
1Route::get('/hoge_list', function () { 2 return view('hoge_list.main'); 3});
想像としては、@includeは単にファイルの中身が読み込まれるだけという認識なので、
section_aの@extendsが動く前に@includeされてしまい、うまく動かないとか、そのあたりを疑っています。
お力をお貸しください。
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。