前提・実現したいこと
ここに質問の内容を詳しく書いてください。
LaravelのMAMP環境で構築しています。
storeメソッド処理中に、下記エラーが発生しました。
な機能を実装中に以下のエラーメッセージが発生しました。
実現したいこととしては。
storeメソッドが機能して、
DBに新規作成のtitleを格納させたいです。
発生している問題・エラーメッセージ
Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException thrown with message ""
該当のソースコード
Laravel
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*/ 13Route::get('/', 'ThreadsController@index'); 14Route::get('/threads/create', 'ThreadsController@create'); 15Route::post('/threads', 'ThreadsController@store'); 16Route::get('/threads/{id}', 'ThreadsController@show')->where('thread','[0-9]+');
Laravel
1<!DOCTYPE html> 2<html lang="ja"> 3<head> 4 <meta charset="utf-8"> 5 <title>掲示板</title> 6 <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous"> 7</head> 8<body> 9<div class="container"> 10 <div class="page-header"> 11 <h1>スレッド新規投稿</h1> 12 </div> 13 <div class="row"> 14 <div class="col-md-12"> 15 <form action="/threads" method="post"> 16 <input type="hidden" name="_token" value="{{ csrf_token() }}"> 17 18 <div class="form-group row"> 19 <label class="col-xs-2 col-form-label">スレッドタイトル</label> 20 <div class="col-xs-10"> 21 <input type="text" name="title" class="form-control" placeholder="スレッドタイトルを入力してください。"/> 22 </div> 23 </div> 24 25 <div class="form-group row"> 26 <div class="col-xs-offset-2 col-xs-10"> 27 <button type="submit" class="btn btn-primary">投稿する</button> 28 </div> 29 </div> 30 </form> 31 </div> 32 </div> 33</div> 34</body> 35</html> 36
Laravel
1<?php 2 3namespace App\Http\Controllers; 4 5use Illuminate\Http\Request; 6use App\Thread; 7class ThreadsController extends Controller 8{ 9 // 10 public function index() { 11 // $threads = Thread::all(); 12 $threads = Thread::latest()->get(); 13 // dd($threads->toArray()); 14 return view('threads.index' , [ 15 'threads' => $threads 16 ]); 17 } 18 19 20 public function create(){ 21 return view('threads.create'); 22 } 23 24 public function store(Request $request) 25 { 26 $thread = new Thread; 27 // $thread = Thread::create(); 28 29 $thread->body = $request->input('body'); 30 $thread->save(); 31 32 return redirect('/threads'); 33 } 34 35 36 public function show($id) { 37 $thread = Thread::find($id); 38 39 return view('threads.show' , [ 40 'thread' => $thread 41 ]); 42 } 43 44} 45
試したこと
showメソッドは問題なく使えているのでDB接続は問題ないのだと思います。
補足情報(FW/ツールのバージョンなど)
PHP:
Laravel:
MAMP:

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/10/28 10:56
退会済みユーザー
2018/10/28 14:05 編集
2018/10/28 22:33