いつもお世話になっております。
Laravelでフォームを作成しています。
helloページでフォームをを表示したいのですが、whoops!ページが表示されます。
原因が分からず教えていただけないでしょうか。
よろしくお願いいたします。
laravelapp\app\Http\Controllers\HelloController.php
namespace App\Http\Controllers; use Illuminate\Http\Request; class HelloController extends Controller { public function index(Request $request){ return view('hello.index',['msg'=>'フォームを入力:']); } public function post(Request $request){ $validate_rule=[ 'name' =>'required', 'mail' =>'email', 'age' =>'numeric|between:0,150', ]; $this->validate($request,$validate_rule); return view('hello.index',['msg'=>'正しく入力されました!']); } }
laravelapp\resources\views\hello\index.blade.php
<h1>Blade/Index</h1> @section('content') <p>{{$msg}}</p> <table> <form method="post" action="hello"> {{csrf_field()}} <tr><th>name: </th><td><input type="text" name="name"></td></tr> <tr><th>mail: </th><td><input type="text" name="mail"></td></tr> <tr><th>age: </th><td><input type="text" name="age"></td></tr> <tr><th></th><td><input type="submit" value="send"></td></tr> </form> </table> @endsection
laravelapp\resources\views\layouts\helloapp.blade.php
<head> <title>@yield('title')</title> <meta name="csrf-token" content="{{ csrf_token() }}"> <link href="http://localhost:8000/favicon.ico" type="image/x-icon" rel="shortcut icon"> <!-- <link rel="stylesheet" type="text/css" href="/css/app.css"> --> <style> body {font-size:16pt; color:#999; margin: 5px; } h1 { font-size:50pt; text-align:right; color:#f6f6f6; margin:-20px 0px -30px 0px; letter-spacing:-4pt; } ul { font-size:12pt; } th {background-color:#999; color:fff; padding:5px 10px; } td {border: solid 1px #aaa; color:#999; padding:5px 10px; } hr { margin: 25px 100px; border-top: 1px dashed #ddd; } .menutitle {font-size:14pt; font-weight:bold; margin: 0px; } .content {margin:10px; } .footer { text-align:right; font-size:10pt; margin:10px; border-bottom:solid 1px #ccc; color:#ccc; } </style> </head> <body> <h1>@yield('title')</h1> @section('menubar') <p class="menutitle">※メニュー</p> <ul> <li>@show</li> </ul> <hr size="1"> <div class="content"> @yield('content') </div> <div class="footer"> @yield('footer') </div> </body> </html>
laravelapp\routes\web.php
<?php /* |-------------------------------------------------------------------------- | Web Routes |-------------------------------------------------------------------------- | | Here is where you can register web routes for your application. These | routes are loaded by the RouteServiceProvider within a group which | contains the "web" middleware group. Now create something great! | */ Route::get('/', function () { return view('welcome'); }); Route::get('hello', 'HelloController@index'); Route::post('hello', 'HelloController@post');
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。