Laravelでエラー GETメソッドはサポートされていない、サポートされているメソッド:POST
解決したいこと
Laravelで画像投稿できるようになりたい。
Routeで怒られているので解決したいです。どなたか教えてください。
このようなエラーが出ます。
Route::group(['prefix'=>'tomoviews'],function(){
Route::get('photo', 'PhotoFormController@photo')->name('views.photo');
Route::post('newpost', 'PhotoFormController@store')->name('views.newpost');
});
public function store(Request $request){
$imgPath = $this->saveImage($request->file('eimg'));
$diary = new Photo();
$diary->eimg = $imgPath;
$diary->save();
return redirect()->route('tomoviews.photo');
}
private function saveImage($image)
{
$imgPath = $image->store('Picture', 'public');
return 'storage/' . $imgPath;
}
public function photo ()
{
$diaries = Diary::all();
return view('photo', ['diaries' => $diaries]);
}
<form method="post" action="{{ route('store') }}" enctype="multipart/form-data">
@csrf
<div class="li-content">
<label>新規画像</label>
<div class="basic">
<input type="file" name="eimg" id="eimg" placeholder="画像選択"></div>
</div>
</form>
@foreach ($diaries as $diary)
<div class="estate-img1">
<img src="{{ asset($Photo->eimg) }}">
</div>
@endforeach
http://127.0.0.1:8000/tomoviews/newpost
開いて画像を投稿してtomoviews/photoに表示させたいです。
宜しくお願いします...
レビュー修正
Route::group(['prefix'=>'tomoviews'],function(){
Route::get('photo', 'PhotoFormController@photo')->name('views.photo');
Route::match(['get','post'],'newpost', 'PhotoFormController@store')->name('views.newpost');
public function store(Request $request){
$imgPath = $this->saveImage($request->file('eimg'));
$diary = new Photo();
$diary->eimg = $imgPath;
$diary->save();
return redirect()->route('tomoviews.photo');
}
private function saveImage($image)
{
$imgPath = $image->store('Picture', 'public');
return 'storage/' . $imgPath;
}
public function photo ()
{
$diaries = Diary::all();
return view('photo', ['diaries' => $diaries]);
}
$imgPath = $image->store('Picture', 'public');
ここで怒られているのですが...
投稿もしていないのでNULLは当たり前なのに、こんな怒られ方がわかりません。
た、助けてください...