Laravel Framework 5.6.23についての質問です。
name="msg"を指定してあったフィールドの値が何故$request->msgで取り出せるのかわかりません。
$msg = $request->msg;について、$request->msgは、URL欄のクエリ文字列である?msg=xxxxx
のxxxxxを取り出すのではないのでしょうか。
つまり、<input type="text" name="msg2">
について、フォームを送信すると、nameの値はURLのクエリ文字として出力されるのでしょうか。
【web.php】
PHP
1<?php 2Route::get('hello','HelloController@index'); 3Route::post('hello','HelloController@kekka'); 4?>
【HelloController.php】
PHP
1<?php 2namespace App\Http\Controllers; 3 4use Illuminate\Http\Request; 5use Illuminate\Http\Response; 6 7class HelloController extends Controller{ 8 public function index(){ 9 $data = ['msg1'=>'お名前を入力してください。']; 10 return view('hello.index',$data); 11 } 12 13 public function kekka(Request $request){ 14 $msg2 = $request->msg2; 15 $data = ['msg1'=>'こんにちは'.$msg2.'さん!']; 16 return view('hello.index',$data); 17 } 18}
【index.blade.php】
PHP
1<html> 2<head> 3 <title>Hello/Index</title> 4 <style> 5 body {font-size:16pt; color:#999;} 6 h1 {font-size:50pt; text-align:right; color:#f6f6f6; margin:-20px 0px -30px 0px; letter-spacing:-4pt;} 7 </style> 8</head> 9<body> 10 <h1>Blade/Index</h1> 11 <p>{{$msg1}}</p> 12 <form method="post" action="/hello"> 13 {{ csrf_field() }} 14 <input type="text" name="msg2"> 15 <input type="submit" value="ポチっとな"> 16 </form> 17</body> 18</html>
回答1件
あなたの回答
tips
プレビュー