
じろう
2019年11月02日に参加
学習履歴詳細
[Laravel]Laravel青本を読む
今日のYWT
やったこと
Laravel青本
わかったこと
Laravel
フォームで送信された値
index.blade.php
<html> <head> <title>Hello/Index</title> </head> <body> <h1>Blade/Index</h1> <p>{{ $msg }}</p> <form method="POST" action="/hello"> @csrf <input type="text" name="msg"> <input type="submit"> </form> </body> </html>
HelloController.php
class HelloController extends Controller { public function index() { $data = [ 'msg' => 'お名前を入力してください', ]; return view('hello.index', $data); } public function post(Request $request) { $msg = $request->msg; $data = [ 'msg' => 'こんにちは、' . $msg . 'さん!', ]; return view('hello.index', $data); } }
ポイント
index.blade.php
で、<input type="text" name="msg">
と指定したことにより、
フィールドの値は$msg = $request->msg;
で、取り出すことができる。
PHP
Docker
Laravel
2020年10月09日(金)
2.0時間