laravel 6.20.44
windows
実現したいこと
products/createのURLを踏むと新規投稿画面が表示されるようにしたい
発生している問題・エラーメッセージ
Route [store] not defined. (View: C:\MAMP\htdocs\blog\resources\views\products\register.blade.php)
一覧画面はきちんと表示されるのですが、新規投稿画面が表示されません。
Youtubeの動画を見ながら勉強しているのですが、動画の通りにしてもエラーが出てしまいます。
自力で調べてルート一覧を参照したり、ルートのキャッシュクリアを試しても改善しませんでした。
laravelのバージョンが関係しているのでしょうか?
動画だとlaravelのバージョンが8、自分のが6なので。
一応、動画のURLも貼っておきます。
https://www.youtube.com/watch?v=1s-_XKtOZ-I&list=PLbURJcNWS9NDCZHUPMTMbX-O6S_47AOIF&index=7
7:15辺りです。
ルート一覧です
web.php
1 <?php 2 3use App\Http\Controllers\ProductsController; 4/* 5|-------------------------------------------------------------------------- 6| Web Routes 7|-------------------------------------------------------------------------- 8| 9| Here is where you can register web routes for your application. These 10| routes are loaded by the RouteServiceProvider within a group which 11| contains the "web" middleware group. Now create something great! 12| 13*/ 14 15Route::get('/', function () { 16 return view('welcome'); 17}); 18 19Auth::routes(); 20 21Route::get('/home', 'HomeController@index')->name('home'); 22 23Route::resource('/products', 'ProductsController'); 24
ProductsController.php
1<?php 2 3namespace App\Http\Controllers; 4 5use App\Models\Products; 6use Illuminate\Http\Request; 7 8class ProductsController extends Controller 9{ 10 /** 11 * Display a listing of the resource. 12 * 13 * @return \Illuminate\Http\Response 14 */ 15 public function index() 16 { 17 return view('products.list'); 18 } 19 20 /** 21 * Show the form for creating a new resource. 22 * 23 * @return \Illuminate\Http\Response 24 */ 25 public function create() 26 { 27 return view('products.register'); 28 } 29 30 /** 31 * Store a newly created resource in storage. 32 * 33 * @param \Illuminate\Http\Request $request 34 * @return \Illuminate\Http\Response 35 */ 36 public function store(Request $request) 37 { 38 39 } 40 41 /** 42 * Display the specified resource. 43 * 44 * @param \App\Models\Products $products 45 * @return \Illuminate\Http\Response 46 */ 47 public function show(Products $products) 48 { 49 50 51 } 52 53 /** 54 * Show the form for editing the specified resource. 55 * 56 * @param \App\Models\Products $products 57 * @return \Illuminate\Http\Response 58 */ 59 public function edit(Products $products) 60 { 61 // 62 } 63 64 /** 65 * Update the specified resource in storage. 66 * 67 * @param \Illuminate\Http\Request $request 68 * @param \App\Models\Products $products 69 * @return \Illuminate\Http\Response 70 */ 71 public function update(Request $request, Products $products) 72 { 73 // 74 } 75 76 /** 77 * Remove the specified resource from storage. 78 * 79 * @param \App\Models\Products $products 80 * @return \Illuminate\Http\Response 81 */ 82 public function destroy(Products $products) 83 { 84 // 85 } 86} 87
register
1<!DOCTYPE HTML> 2<html lang="ja"> 3<head> 4 <meta charset="UTF-8"> 5 <title>ブログ</title> 6 <link rel="stylesheet" href="/css/app.css"> 7 <script src="/js/app.js" defer></script> 8</head> 9<body> 10 <br> 11 <div class="container"> 12 <div class="row"> 13 <div class="col-md-8 col-md-offset-2"> 14 <h2>商品登録</h2> 15 16 <form class="edit-form" method="POST" action="{{ route('store') }}" 17 onSubmit="return checkSubmit()"> 18 @csrf 19 20 <div class="form-group"> 21 <p>商品名</p> 22 <input type="text" name="product_name" required> 23 </div> 24 <div class="form-group"> 25 <p>メーカー</p> 26 <select name="maker"> 27 <option value="サンプル1">サンプル1</option> 28 <option value="サンプル2">サンプル2</option> 29 <option value="サンプル3">サンプル3</option> 30 </select> 31 </div> 32 <div class="form-group"> 33 <p>価格</p> 34 <input type="text" name="text" maxlength="8"> 35 </div> 36 <div class="form-group"> 37 <p>在庫数</p> 38 <input type="text" name="text" maxlength="8"> 39 </div> 40 <div class="form-group"> 41 <p>コメント</p> 42 <textarea name="kansou" rows="4" cols="40"> 43 </textarea> 44 </div> 45 <div class="form-group"> 46 <p>商品画像</p> 47 <input type="file" name="img" class="imgform"> 48 </div> 49 <button type="submit">登録</button> 50 <button onclick="location.href='/products'">戻る</button> 51 </form> 52 53 </tr> 54 </div> 55</div> 56 </div> 57 58</body> 59</html>

回答1件
あなたの回答
tips
プレビュー