回答編集履歴
3
home.blade.phpみすってたので修正
test
CHANGED
@@ -112,7 +112,9 @@
|
|
112
112
|
|
113
113
|
@section('content')
|
114
114
|
|
115
|
+
{{$name['name']}}
|
116
|
+
|
115
|
-
|
117
|
+
<br />
|
116
118
|
|
117
119
|
@endsection
|
118
120
|
|
2
yieldを勘違いしてたため修正したのもおかしいので再度編集
test
CHANGED
@@ -10,24 +10,110 @@
|
|
10
10
|
|
11
11
|
|
12
12
|
|
13
|
-
###
|
13
|
+
### laravel6で確認したソース
|
14
14
|
|
15
15
|
|
16
16
|
|
17
|
+
web.php(router)
|
18
|
+
|
17
19
|
```php
|
18
20
|
|
21
|
+
Route::get('/home', function() {
|
22
|
+
|
19
|
-
|
23
|
+
$name = ['name' => 'hoge'];
|
24
|
+
|
25
|
+
return view('home', compact('name'));
|
26
|
+
|
27
|
+
});
|
28
|
+
|
29
|
+
```
|
20
30
|
|
21
31
|
|
22
32
|
|
33
|
+
app.blade.php(view)
|
34
|
+
|
35
|
+
```php
|
36
|
+
|
37
|
+
<!DOCTYPE html>
|
38
|
+
|
39
|
+
<html lang="ja">
|
40
|
+
|
41
|
+
<head>
|
42
|
+
|
43
|
+
<meta charset="UTF-8">
|
44
|
+
|
45
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
46
|
+
|
47
|
+
<meta http-equiv="X-UA-Compatible" content="ie=edge">
|
48
|
+
|
49
|
+
<script src="https://kit.fontawesome.com/35b19442e0.js" crossorigin="anonymous"></script>
|
50
|
+
|
23
|
-
|
51
|
+
<title>@yield('title')</title>
|
52
|
+
|
53
|
+
@yield('style')
|
54
|
+
|
55
|
+
</head>
|
56
|
+
|
57
|
+
<body>
|
58
|
+
|
59
|
+
@component('components.header', $name)
|
60
|
+
|
61
|
+
@endcomponent
|
62
|
+
|
63
|
+
|
64
|
+
|
65
|
+
@yield('content')
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
@component('components.footer', $name)
|
70
|
+
|
71
|
+
@endcomponent
|
72
|
+
|
73
|
+
</body>
|
74
|
+
|
75
|
+
</html>
|
24
76
|
|
25
77
|
```
|
26
78
|
|
79
|
+
|
80
|
+
|
27
|
-
|
81
|
+
header.blade.php(view)
|
82
|
+
|
83
|
+
```php
|
84
|
+
|
85
|
+
header:{{$name}}
|
86
|
+
|
87
|
+
<br />
|
88
|
+
|
89
|
+
```
|
28
90
|
|
29
91
|
|
30
92
|
|
31
|
-
|
93
|
+
footer.blade.php(view)
|
32
94
|
|
95
|
+
```php
|
96
|
+
|
97
|
+
footer:{{$name}}
|
98
|
+
|
99
|
+
<br />
|
100
|
+
|
101
|
+
```
|
102
|
+
|
103
|
+
|
104
|
+
|
105
|
+
home.blade.php(view)
|
106
|
+
|
107
|
+
```php
|
108
|
+
|
33
|
-
|
109
|
+
@extends('layouts.app')
|
110
|
+
|
111
|
+
|
112
|
+
|
113
|
+
@section('content')
|
114
|
+
|
115
|
+
ほげ
|
116
|
+
|
117
|
+
@endsection
|
118
|
+
|
119
|
+
```
|
1
質問者とやり取りで実際は違ったので編集
test
CHANGED
@@ -3,3 +3,31 @@
|
|
3
3
|
|
4
4
|
|
5
5
|
その受け渡しではviewでは`$name['name']`になる感じがします
|
6
|
+
|
7
|
+
|
8
|
+
|
9
|
+
---
|
10
|
+
|
11
|
+
|
12
|
+
|
13
|
+
### 実際の解決方法
|
14
|
+
|
15
|
+
|
16
|
+
|
17
|
+
```php
|
18
|
+
|
19
|
+
$name = $request->only('name');
|
20
|
+
|
21
|
+
|
22
|
+
|
23
|
+
return view('home', compact('name'));
|
24
|
+
|
25
|
+
```
|
26
|
+
|
27
|
+
はviewの`@include`に引数で渡すために`only`のままででいい
|
28
|
+
|
29
|
+
|
30
|
+
|
31
|
+
テンプレートの`@yield('content')`では`content`に変数が渡せないので
|
32
|
+
|
33
|
+
`@include('heade.blade.php', $name)`にする
|