前提・実現したいこと
laravelのcrudアプリ作ってます。
かくview作成したのでとりあえずリンク貼って行き来できるようにしたいです。
発生している問題・エラーメッセージ
Route [user.index] not defined. とエラーが出ています。
<h1>test</h1>
create
1<h1>新規登録画面</h1> 2<p><a href="{{ route('user.index') }}">一覧画面</a></p> 3
UserController
1<?php 2 3namespace App\Http\Controllers; 4 5use App\Models\User; 6use Illuminate\Http\Request; 7//use App\User; 8class UserController extends Controller 9{ 10 /** 11 * Display a listing of the resource. 12 * 13 * @return \Illuminate\Http\Response 14 */ 15 public function index() 16 { 17 $users = User::all(); 18 return view('user/index', compact('users')); 19 20 } 21 22 /** 23 * Show the form for creating a new resource. 24 * 25 * @return \Illuminate\Http\Response 26 */ 27 public function create() 28 { 29 return view('user.create'); 30 } 31 32 /** 33 * Store a newly created resource in storage. 34 * 35 * @param \Illuminate\Http\Request $request 36 * @return \Illuminate\Http\Response 37 */ 38 public function store(Request $request) 39 { 40 Book::create($request->all()); 41 return redirect()->route('user.index')->with('success', '新規登録完了しました'); 42 } 43 44 /** 45 * Display the specified resource. 46 * 47 * @param int $id 48 * @return \Illuminate\Http\Response 49 */ 50 public function show($id) 51 { 52 $user = User::find($id); 53 return view('user.show', compact('user')); 54 } 55 56 /** 57 * Show the form for editing the specified resource. 58 * 59 * @param int $id 60 * @return \Illuminate\Http\Response 61 */ 62 public function edit($id) 63 { 64 $users = User::find($id); 65 return view('user/edit', compact('users')); 66 } 67 68 /** 69 * Update the specified resource in storage. 70 * 71 * @param \Illuminate\Http\Request $request 72 * @param int $id 73 * @return \Illuminate\Http\Response 74 */ 75 public function update(Request $request, $id) 76 { 77 $update = [ 78 'title' => $request->title, 79 'author' => $request->author 80 ]; 81 User::where('id', $id)->update($update); 82 return back()->with('success', '編集完了しました'); 83 } 84 85 /** 86 * Remove the specified resource from storage. 87 * 88 * @param int $id 89 * @return \Illuminate\Http\Response 90 */ 91 public function destroy($id) 92 { 93 // 94 } 95} 96
webphp
1<?php 2 3use Illuminate\Support\Facades\Route; 4use App\Http\Controllers\UserController; 5 6/* 7|-------------------------------------------------------------------------- 8| Web Routes 9|-------------------------------------------------------------------------- 10| 11| Here is where you can register web routes for your application. These 12| routes are loaded by the RouteServiceProvider within a group which 13| contains the "web" middleware group. Now create something great! 14| 15*/ 16 17Route::resource('/user/', UserController::class); 18//Route::get('/', function () { 19// return view('welcome'); 20//}); 21
routelist
1+--------+-----------+---------------------+--------------+------------------------------------------------------------+------------------------------------------+ 2| Domain | Method | URI | Name | Action | Middleware | 3+--------+-----------+---------------------+--------------+------------------------------------------------------------+------------------------------------------+ 4| | GET|HEAD | / | | Closure | web | 5| | GET|HEAD | api/user | | Closure | api | 6| | | | | | App\Http\Middleware\Authenticate:sanctum | 7| | GET|HEAD | sanctum/csrf-cookie | | Laravel\Sanctum\Http\Controllers\CsrfCookieController@show | web | 8| | GET|HEAD | user | user.index | App\Http\Controllers\UserController@index | web | 9| | POST | user | user.store | App\Http\Controllers\UserController@store | web | 10| | GET|HEAD | user/create | user.create | App\Http\Controllers\UserController@create | web | 11| | GET|HEAD | user/{user} | user.show | App\Http\Controllers\UserController@show | web | 12| | PUT|PATCH | user/{user} | user.update | App\Http\Controllers\UserController@update | web | 13| | DELETE | user/{user} | user.destroy | App\Http\Controllers\UserController@destroy | web | 14| | GET|HEAD | user/{user}/edit | user.edit | App\Http\Controllers\UserController@edit | web | 15+--------+-----------+---------------------+--------------+------------------------------------------------------------+------------------------------------------+ 16
試したこと
ルート確認してみましたが以上ないと思われる。
他に何かたりてないのでしょうか?
ご教授していただけると幸いです。
補足情報(FW/ツールのバージョンなど)
Laravel8
回答1件
あなたの回答
tips
プレビュー