LaravelでCRUDの勉強をしています。
以下に詳細を記載しますので、原因や対策など教えて頂けると助かります。。。
■投稿の流れ
入力フォーム → 確認画面 → 完了画面
■エラーになる部分
確認画面までは画像のパスが取得できていますが
そこから登録ボタンをクリックするとエラー画面になります。(完了画面に遷移しない)
■エラー内容
Symfony \ Component \ HttpKernel \ Exception \ MethodNotAllowedHttpException
No message
上記のような文が出てくるので何が原因なのかもわからない状態です。
■試したこと
・入力フォーム、確認画面ともに「enctype="multipart/form-data"」を指定
・「php aritsan storage:link」コマンド実行
■コードは以下
create.blade.php
php
1@extends('layouts.app') 2 3@section('content') 4<div class="clientWrap"> 5<h3>Add</h3> 6<p> 7 <span class="label label-danger">入力画面</span> -> 確認画面 -> 完了画面 8</p> 9 10<form class="" onkeypress=""action="{{ url('/client/confirm') }}" method="post" enctype="multipart/form-data"> 11 {{ csrf_field() }} 12 <p> 13 <input type="text" name="name" placeholder="名前" value="{{ old('name') }}"> 14 @if ($errors->has('name')) 15 <span class="error">{{ $errors->first('name') }}</span> 16 @endif 17 </p> 18 <p> 19 <input type="text" name="age" placeholder="年齢" value="{{ old('age') }}"> 20 @if ($errors->has('age')) 21 <span class="error">{{ $errors->first('age') }}</span> 22 @endif 23 </p> 24 <p> 25 <input type="text" name="email" placeholder="アドレス" value="{{ old('email') }}"> 26 @if ($errors->has('email')) 27 <span class="error">{{ $errors->first('email') }}</span> 28 @endif 29 </p> 30 <p><textarea name="memo" rows="8" cols="80" placeholder="備考">{{ old('memo') }}</textarea></p> 31 32 <p> 33 <label class="col-sm-3 control-label" for="image">画像アップロード</label> 34 <input type="file" name="photo" class="form-control{{ $errors->has('image') ? ' is-invalid' : '' }}" placeholder="ファイル"> 35 @if ($errors->has('image')) 36 <span class="invalid-feedback"> 37 <strong>{{ $errors->first('image') }}</strong> 38 </span> 39 @endif 40 </p> 41 42 43 44 <input type="submit" name="" value="確認"> 45 46</form> 47</div> 48@endsection
confirm.blade.php
php
1@extends('layouts.app') 2 3 4@section('content') 5<div class="clientWrap"> 6 <h3>confirm</h3> 7 <p> 8 入力画面 -> <span class="label label-danger">確認画面</span> -> 完了画面 9 </p> 10 11 <form class="" onkeypress=""action="{{ url('/client/finish') }}" method="post" enctype="multipart/form-data"> 12 13 <input type="hidden" name="_token" value="{{ csrf_token() }}"> 14 <input type="hidden" name="name" value="{{ $name }}"> 15 <input type="hidden" name="email" value="{{ $email }}"> 16 <input type="hidden" name="age" value="{{ $age }}"> 17 <input type="hidden" name="memo" value="{{ $memo }}"> 18 <input type="hidden" name="photo" value="{{ $photo }}"> 19 20 <p>名前:{{$name}}</p> 21 <p>年齢:{{$age}}</p> 22 <p>メールアドレス:{{$email}}</p> 23 <p>備考:{!! nl2br(e($memo)) !!}</p> 24 <p>画像のパス:{{ $photo }}</p> 25 26 27 <input type="submit" name="action" value="戻る"> 28 <input type="submit" name="action" value="登録"> 29 30 </form> 31</div> 32@endsection
ClientsController.php
php
1 2<?php 3 4namespace App\Http\Controllers; 5 6use Illuminate\Http\Request; 7use App\Client; 8use App\Http\Requests\ClientRequest; 9 10class ClientsController extends Controller 11{ 12 13 public function __construct() { 14 $this->middleware('auth'); 15 } 16 17 // 18 public function index() { 19 $clients = Client::latest()->get();//Clientモデルにあるデータを登録の新しい順に取得してくる 20 return view('client.list')->with('clients', $clients); 21 } 22 23 public function show(Client $client) { 24 return view('client.show')->with('client', $client); 25 } 26 27 public function create() { 28 return view('client.create'); 29 } 30 31 public function confirm(ClientRequest $request) { 32 $data = $request->all(); 33 34 return view('client.confirm')->with($data); 35 } 36 37 public function store(ClientRequest $request) { 38 $action = $request->get('action');// name=action の value名を取得 39 $input = $request->except('action');// 入力内容を取得 40 41 if($action === '登録') { 42 $path = "app/".$request->file('image')->store('public/images'); 43 $client = new Client(); 44 $client->clientName = $request->name; 45 $client->clientAge = $request->age; 46 $client->clientEmail = $request->email; 47 $client->clientMemo = $request->memo; 48 $client->clientImagePath = basename($path); 49 $client->save(); 50 51 return view('client.finish'); 52 } else { 53 return redirect('/client/create')->withInput($input); 54 } 55 56 } 57}
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/03/07 07:44
2019/03/08 02:25