現在laravelの学習中でフォームから入力した値をPOST送信しているのですが。送信後の画面で419のエラーが出て期限切れと表示されてしまいます。
調べたところcsrfを記入していないと起こったりすると出てきたのですがそこも書いてあるのに出てしまいます。
ご存知の方お力をお貸しください。一応bladeとcontrollerの内容を載せます。その他必要な部分があれば言っていただければともいます。どうかよろしくお願いいたします。
・実行したこと
1.App\Http\Kernel.phpのVerifyCsrfToken をコメントアウトしたがHelloRequestがが見つからないと言うエラーが出る
php
1@extends('layouts.helloapp')<!-- 引数1フォルダ内の引数2ファイル --> 2 3 4@section('title','Index')<!--引数1:当てはめるセクション 引数2:そこに表示する値--> 5 6@section('menubar') 7 @parent<!--親のセクションを消したくない時に利用する--> 8 インデックスページ 9 10 11@endsection 12 13 14 15 16@section('content') 17 <p>{{$msg}} </p> 18 @if (count($errors) > 0 ) 19 <p>入力に誤りがあります。</p> 20 @endif 21 22 <table> 23 <form method="POST" action="/hello" > 24 @csrf 25 @if($errors->has('name')) 26 <tr><th>ERROR:</th><td>{{$errors->first('name')}} </td></tr> 27 @endif 28 <tr><th>name:</th><td><input type="text" name="name" value="{{old('name')}} " ></td></tr> 29 30 @if($errors->has('mail')) 31 <tr><th>ERROR:</th><td>{{$errors->first('mail')}} </td></tr> 32 @endif 33 <tr><th>mail:</th><td><input type="text" name="mail" value="{{old('mail')}} "></td></tr> 34 35 @if($errors->has('age')) 36 <tr><th>ERROR:</th><td>{{$errors->first('age')}} </td></tr> 37 @endif 38 <tr><th>age:</th><td><input type="text" name="age" value="{{old('age')}} " ></td></tr> 39 <tr><th></th><td><input type="submit" value="send"></td></tr> 40 </form> 41 </table> 42@endsection 43 44 45 46 47@section('footer') 48copyright 2019 Takehiro. 49 50@endsection
php
1 2<?php 3 4namespace App\Http\Controllers; 5 6use Illuminate\Http\Request; 7use Illuminate\Http\Response; 8use App\Http\Request\HelloRequest; 9 10 11 12 13 14 15class HelloController extends Controller 16{ 17 // 18 19 20 public function index(Request $request){ 21 return view('hello.index',['msg'=>'フォームを入力:']); 22} 23 24 25 public function post(HelloRequest $request){ 26 27 28 return view('hello.index',['msg'=>'正しく入力されました']); 29 30 $response->assertRedirect('/'); 31 } 32 33 } 34?>
あなたの回答
tips
プレビュー