前提・実現したいこと
訪れていただき誠にありがとうございます。
初心者につき見苦しいところがあるかと思いますが、何卒ご了承ください。
Viewの"form"から"post"でデータを送ろうとしたところでエラーが発生しました。
□やろうとしていること
前提:英文法の学習サイトを作ろうとしています。
エラーが発生している過程:
ユーザーが【showQuestions.blade.php】で入力した回答内容を、
postで【correctQuestions.blade.php】に送る過程。
エラーメッセージ
InvalidArgumentException View [questions.correctQuestions] not found.
web.php
Auth::routes(); Route::get('/', 'IndexController@home')->name('home'); Route::get('/index', 'IndexController@index')->name('index'); Route::get('/explain/{genre_value}', 'IndexController@explain')->name('explain'); Route::get('/questions/question/{genre_value}','QuestionController@showQuestions'); Route::POST('/questions/answer','QuestionController@correctQuestions');
送信元のviewファイル: /app/resources/views/questions/showQuestions.blade.php
<form action = "{{url('/questions/answer')}}" method="post"> @csrf @foreach($questions as $key => $bigQ_record) <div class="answer"> <?php $count = count($bigQ_record["questions"]) ?> <?php $trueCount = $count-1 ?> <?php echo $key.".".$bigQ_record["big_question"] ?><br> <?php for($i = 0; $i <= $trueCount; $i++) :?> <?php $num = $i+1 ?> <?php $user_answer = $num.$bigQ_record["questions"][$i] ?> <?php echo "(".$num.")".$bigQ_record["questions"][$i] ?><br> <input type = "text" name = "small_answers[<?php echo $key ?>][<?php echo $num ?>]"></input> <br> <?php endfor ?> <br> <br> @endforeach <input type = "hidden" name = "genre_value" value = "{{$genre_value}}"> <input type = "submit" name="" value = "答え合わせをする" /> </form>
送信先(遷移先)のViewのパス:
/app/resources/views/questions/correctQuestions.blade.php
上記2つのviewに対応するメソッドのある【QuestionController.php】
(長々と処理が書いてありますが、メソッドの宣言部分とreturnの部分に注目していただければよいかと思います)
<?php namespace App\Http\Controllers; use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth; use App\Models\Genre; use App\Models\Small_question; use App\Models\Big_question; use DB; class QuestionController extends Controller { public function __construct() { $this->middleware('auth'); } //送信元のView(showQuestions.blade.php)に対応するメソッド public function showQuestions($genre_value){ $user_data = Auth::user(); $user_name = $user_data -> name; $small_questions_array = DB::table('small_questions') ->join('big_questions','small_questions.big_question_id','=','big_questions.id') ->where('small_questions.genre_value','=',$genre_value) ->select('small_questions.*', 'big_questions.big_question') ->get(); foreach($small_questions_array as $record_value){ $big_que=$record_value->big_question_id; $big_q=$record_value->big_question; $small_q=$record_value->question; $questions1[$big_que]=["big_question"=>$big_q]; $questions2[$big_que][]=$small_q; } for($i=1; $i<=3; $i++ ){ $questions[$i]=$questions1[$i]; $questions[$i]["questions"]=$questions2[$i]; } return view('questions.showQuestions',compact('genre_value','user_name','questions')); } //送信先のView(correctQuestions.blade.php)に対応するメソッド public function correctQuestions(Request $small_answers){ $user_data = Auth::user(); $user_id = $user_data -> id; $genre_value = $small_answers->genre_value; $big_records = DB::table('big_questions') ->select('big_questions.*') ->get(); $small_records = DB::table('small_questions') ->join('big_questions','small_questions.big_question_id','=','big_questions.id') ->where('small_questions.genre_value','=',$genre_value) ->select('small_questions.*', 'big_questions.big_question') ->get(); foreach( $small_records as $record_value){ $big_que=$record_value->big_question_id; $big_q=$record_value->big_question; $small_q=$record_value->question; $small_a=$record_value->answer; $questions1[$big_que]=["big_question"=>$big_q]; $questions2[$big_que][]=$small_q; $answers[$big_que][]=$small_a; } for($i=1; $i<=3; $i++ ){ $questions[$i]=$questions1[$i]; $questions[$i]["questions"]=$questions2[$i]; $questions[$i]["answers"]=$answers[$i]; } ** return view('questions.correctQuestions',compact('questions','genre_value','small_answers','big_records')); ** }
エラー画面
C:\Xampp\htdocs\beyou_ver2\vendor\laravel\framework\src\Illuminate\View\FileViewFinder.php /** * Find the given view in the list of paths. * * @param string $name * @param array $paths * @return string * * @throws \InvalidArgumentException */ protected function findInPaths($name, $paths) { foreach ((array) $paths as $path) { foreach ($this->getPossibleViewFiles($name) as $file) { if ($this->files->exists($viewPath = $path.'/'.$file)) { return $viewPath; } } } throw new InvalidArgumentException("View [{$name}] not found."); } /** * Get an array of possible view files. * * @param string $name * @return array */ protected function getPossibleViewFiles($name) { return array_map(function ($extension) use ($name) { return str_replace('.', '/', $name).'.'.$extension; }, $this->extensions); }
試したこと
1.xampp,windows,php artisan serveの再起動
2.viewファイル名のタイポの再確認
3.エラー画面の調査(処理のログ(?)、発生個所の”FileViewFinder.php”を調べた。
手掛かりがつかめずじまい。
4.「InvalidArgumentException View [○○] not found.」を検索。
ヒットするがヒントになる記事が見受けられず。
5.ルーティングを疑う→疑ってはいるものの勘の域をでない。
一応記載の順番に問題がないか確認し、問題ないと認識。
6.LaravelのPOSTの扱い方の誤りの可能性あり→
これも勘の域を出ない。dotinstallや、ほかの情報を参考に再現しているので間違えてはいないはずだが・・・
(調査進行中)
4時間かけても解決できず、
当サービスで質問させていただいている次第です。
補足情報(FW/ツールのバージョンなど)
Laravel Framework 5.8.11
gitレポジトリ
https://github.com/NaotoSuzuki/beyou_ver2
ほかに必要な情報があればお申し付けください。
よろしくお願いいたします。
ここまでお目通しいただきありがとうございました。
本件に関すること以外にも、気になった部分へのご指摘は歓迎させていただきます。

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/05/06 00:19