お問い合わせフォームを作成しております。
フォームに入力後次の確認ページに行くときに
Class App\Http\Controllers\ContactRequest does not existのエラーが出ます。
問い合わせフォームページ画面
確認画面
送信完了画面
を作成しました。
実装したものは下記です。
お問い合わせフォームページ画面
@extends('layouts.app') @section('content') <div class="container"> <div class="row"> <h1>お問い合わせ</h1> </div> <div class="row"> <form action="contact/confirm" method="post"> <div class="form-group"> <label for="InputName">名前</label> <input type="text" name="name" class="form-control" id="InputName" value="{{ old('name') }}"> @if($errors->has('name')) <p class="text-danger">{{ $errors->first('name')}}</p> @endif </div> <div class="form-group"> <label for="InputEmail">メールアドレス</label> <input type="email" name="email" class="form-control" id="InputEmail" value="{{ old('email') }}"> @if($errors->has('email')) <p class="text-danger">{{ $errors->first('email')}}</p> @endif </div> <div class="form-group"> <label for="InputType">件名</label> <input type="text" name="type" class="form-control" id="InputType" value="{{ old('type') }}"> @if($errors->has('type')) <p class="text-danger">{{ $errors->first('type')}}</p> @endif </div> <div class="form-group"> <label for="InputBody">メッセージ</label> <textarea name="body" id="InputBody" class="form-control" cols="40" rows="4"> {{ old('body') }} </textarea> @if($errors->has('body')) <p class="text-danger">{{ $errors->first('body')}}</p> @endif </div> {{ csrf_field() }} <button type="submit" name="action" class="btn btn-primary" value="sent">送信する</button> </form> </div> </div> @endsection
確認画面
@extends('layouts.app') @section('content') <div class="container"> <div class="row"> <h1>お問い合わせ内容の確認</h1> </div> <div class="row"> <p>下記、お問い合わせ内容にて送信します。よろしければ「送信」ボタンを押して下さい。</p> <table class="table table-bordered"> <tr> <td class="table-secondary" style="width:20%">名前</td> <td>{{ $name }}</td> </tr> <tr> <td class="table-secondary" style="width:20%">メールアドレス</td> <td>{{ $email }}</td> </tr> <tr> <td class="table-secondary">件名</td> <td>{{ $type }}</td> </tr> <tr> <td class="table-secondary">メッセージ</td> <td>{!! nl2br(e(body)) !!}</td> </tr> </table> <form action="sent" method="post"> <input type="hidden" name="name" class="form-control" id="InputName" value="{{ $name }}"> <input type="hidden" name="email" class="form-control" id="InputEmail" value="{{ $email }}"> <input type="hidden" name="type" class="form-control" id="InputType" value="{{ $type }}"> <input type="hidden" name="body" class="form-control" id="InputBody" value="{{ $body }}"> {{ csrf_field() }} <button type="submit" name="action" class="btn btn-primary" value="back">戻る</button> <button type="submit" name="action" class="btn btn-primary" value="sent">送信</button> </form> </div> </div> @endsection
送信完了画面
@extends('layouts.app') @section('content') <div class="container"> <div class="row"> <h1>お問い合わせ送信完了</h1> </div> <div class="row"> <p>お問い合わせありがとうございました。</p> </div> <div class="row"> <p>ご入力いただいた内容は正しく送信されました。</p> </div> </div> @endsection
web.php
//お問い合わせページ //入力画面 Route::get('contact','ArticlesController@contact')->name('articles.contact'); //確認画面 Route::post('contact/confirm','ArticlesController@confirm')->name('articles.confirm'); //送信終了 ページ Route::post('contact/complete', 'ArticlesController@complete')->name('articles.complete');
Controller.php
public function contact() { return view('contacts.contact'); } public function confirm(ContactRequest $request) { //誰でも送ることが可能 $contact = $request->all(); $request->session()->regenerateToken(); return view('contact.confirm',$contact); } public function complete(ContactRequest $request) { $contact = $request->all(); if ($request->action === '戻る') { return redirect()->route('contact')->withInput($contact); $request->session()->regenerateToken(); Mail::to('自分のメールアドレス')->send(new Contact($contact)); return view('contact.complete'); // データを保存 Article::create($request->all()); } } }
試したこと
Controller.phpに
use App\Http\Controllers\ContactRequest;
を追記した。けど解消れなかった。
回答1件
あなたの回答
tips
プレビュー