このエラー画面がでてきて、困っています。
前もコマンドで作ったファイル、
php artisan make:provider HelloServiceProvider
でも、上記のようなエラーが発生しており、ここのコマンドで作ったファイルに原因があるのでは、ないかと思うのですが、どのように解決したら良いかわからないため質問させていただきます。
php artisan make:request HelloRequest を打ち込む
Http/Request/HelloRequest
「HelloRequest」を作りました。
HelloRequetはバリデーションの役割をもっています
php
1HelloRequest 2 3<?php 4 5namespace App\Http\Requests; 6 7use Illuminate\Foundation\Http\FormRequest; 8 9class HelloRequest extends FormRequest 10{ 11 public function authorize() 12 { 13 if ($this->path() == 'hello') 14 { 15 return true; 16 } else { 17 return false; 18 } 19 } 20 21 public function rules() 22 { 23 return [ 24 'name' => 'required', 25 'mail' => 'email', 26 'age' => 'numeric|between:0,150', 27 ]; 28 } 29} 30
HelloController.phpがコントローラーの役割を果たしています。
php
1<?php 2 3HelloController.php 4 5namespace App\Http\Controllers; 6 7use Illuminate\Http\Request; 8use Illuminate\Http\Response; 9 10 11class HelloController extends Controller 12{ 13 14 public function index(Request $request) 15{ 16 return view('hello.index',['msg'=>'フォームを入力:']); 17} 18// use App\Http\Requests\HelloRequest; を追加しておく 19 20public function post(HelloRequest $request) 21{ 22 return view('hello.index', ['msg'=>'正しく入力されました!']); 23} 24} 25
ーーーー追記ーーーーー
ルートでは、web.phpしかいじっていないので、web.phpをのせます
php
1<?php 2 3/* 4|-------------------------------------------------------------------------- 5| Web Routes 6|-------------------------------------------------------------------------- 7| 8| Here is where you can register web routes for your application. These 9| routes are loaded by the RouteServiceProvider within a group which 10| contains the "web" middleware group. Now create something great! 11| 12*/ 13 14Route::get('/', function () { 15 return view('welcome'); 16}); 17 18Route::get('hello', 'HelloController@index'); 19Route::post('hello', 'HelloController@post'); 20 21// use App\Http\Middleware\HelloMiddleware; を追記 22 23Route::get('hello', 'HelloController@index');
viewだとこれをいじったので、index.blade.phpを載せます
php
1@extends('layouts.helloapp') 2@section('title','Index') 3@section('menubar') 4 @parent 5 インデックスページ 6@endsection 7 8@section('content') 9 <p>{{$msg}}</p> 10 @if (count($errors) > 0) 11 <p>入力に問題があります。再入力して下さい。</p> 12 @endif 13 <table> 14 <form action="/hello" method="post"> 15 {{ csrf_field() }} 16 @if ($errors->has('name')) 17 <tr><th>ERROR</th><td>{{$errors->first('name')}}</td></tr> 18 @endif 19 <tr><th>name: </th><td><input type="text" name="name" 20 value="{{old('name')}}"></td></tr> 21 @if ($errors->has('mail')) 22 <tr><th>ERROR</th><td>{{$errors->first('mail')}}</td></tr> 23 @endif 24 <tr><th>mail: </th><td><input type="text" name="mail" 25 value="{{old('mail')}}"></td></tr> 26 @if ($errors->has('age')) 27 <tr><th>ERROR</th><td>{{$errors->first('age')}}</td></tr> 28 @endif 29 <tr><th>age: </th><td><input type="text" name="age" 30 value="{{old('age')}}"></td></tr> 31 <tr><th></th><td><input type="submit" value="send"></td></tr> 32 </form> 33 </table> 34@endsection 35 36 37@section('footer') 38copyright 2017 tuyono. 39@endsection 40
回答1件
あなたの回答
tips
プレビュー