私は投稿を見たことがありますが、投稿データを投稿経路に正しく渡していると思うので問題とは関係ありません。ここでLaravel:コントローラを介してデータを渡すとMethodNotAllowedHttpExceptionが発生する
は、関連する経路コードです:
Route::get('/pass', '[email protected]');
Route::post('/pass/{request}',['uses' => '[email protected]']);
私は「パス」のページに1つのコントローラメソッドを持っていると思いますが、私はそれらを分離している問題を特定します。ここ
はPageController.phpに関連する方法である:
public function pass(){
return view('pass')->with(array(
'title'=>'Create A Pass'
));
}
public function passRequest($request){
$data['request'] = $request;
$validator = Validator::make($request->all(), [
'studentID' => 'required|max:255',
'teacherID' => 'required|max:255',
'destination' => 'required|max:255',
]);
if ($validator->fails()) {
return redirect('/')
->withInput()
->withErrors($validator);
}
$pass = new Pass;
$pass->student = DB::table('users')->where('studentID', $request->studentID)->first()->id;
$pass->teacher = DB::table('users')->where('teacherID', $request->teacherID)->first()->id;
$pass->destination = $request->destination;
$pass->save();
return view('home')->with(array(
'title'=>'Home',
'success'=>'null'
));
}
Iメソッドは、コントローラにデータを渡すためにhereを述べました。これは悪い習慣/時代遅れの私は任意の提案に開いている。
これは私がMethodNotAllowedHttpException例外を取得し、このフォームの提出に
<form action="{{ url('pass') }}" method="POST" class="form-horizontal">
{!! csrf_field() !!}
<fieldset>
<!-- Text input-->
<div class="container">
<div class="form-group">
<label class="col-md-4 control-label" for="studentID">Student ID</label>
<div class="col-md-3">
<input id="studentID" name="studentID" type="text" class="form-control input-md">
</div>
</div>
</div>
<!-- Text input-->
<div class="container">
<div class="form-group">
<label class="col-md-4 control-label" for="teacherID">Teacher ID</label>
<div class="col-md-3">
<input id="teacherID" name="teacherID" type="text" class="form-control input-md">
</div>
</div>
</div>
<!-- Text input-->
<div class="container">
<div class="form-group">
<label class="col-md-4 control-label" for="destination">Destination</label>
<div class="col-md-3">
<input id="destination" name="destination" type="text" class="form-control input-md">
</div>
</div>
</div>
<div class="container">
<div class="form-group">
<div class="col-sm-offset-4 col-sm-6">
<button type="submit" class="btn btn-default">
<i class="fa fa-check"></i> Create Pass
</button>
</div>
</div>
</div>
</fieldset>
</form>
ポストデータを送信するための責任が「パス」ページ内のフォームです。
エラーのスタックトレースが役立つ場合は、私にお知らせください。スタイルに関する提案があれば、私はそれにも開放しています。
ありがとうございます。私はルーティングプロセス全体を理解し始めていると思います。私はgetメソッドと{request}変数を接続することを忘れました。私がやっていたことを理解するのではなく、サンプルコードをコピーして貼り付け、それをその目的のために使用していました。私はそれがまだ働いているとは言えません、少なくともこの問題は解決されました。 – Damen