https://qiita.com/Alesion30/items/95222f62904ef46f6f45←学習サイト
環境ーWindows 、XAMPP
Symfony\Component\Routing\Exception\RouteNotFoundException Route [submit] not defined. (View: C:\xampp\htdocs\memoApp\resources\views\home.blade.php) http://localhost/memoApp/public/home
Symfony\Component\Routing\Exception\RouteNotFoundException Route [home] not defined. (View: C:\xampp\htdocs\memoApp\resources\views\submit.blade.php) http://localhost/memoApp/public/submit
該当ソース
home.blade.php
@extends('layouts.app') @section('css') <style> header { height: 50px; background-color: #000; color: white; padding-left: 20px; font-size: large; color: #ddd; } .title { position: absolute; top: 10px; } .card { margin-top: 40px; } .left { width: 70%; } .submit { position: absolute; top: 10px; right: 20px; } </style> @endsection @section('content') <div class="card" style="width: 100%;"> <div class="card-header"> メモ一覧 <a href="{{ route('submit')}}" class="submit">メモを追加</a> </div> <table class="table"> <tbody> <tr> <td class="left">メモ1</td> <td><a href="{{ route('submit')}}">編集</a></td> <td><a>削除</a></td> </tr> <tr> <td class="left">メモ2</td> <td><a href="{{ route('submit')}}">編集</a></td> <td><a>削除</a></td> </tr> <tr> <td class="left">メモ3</td> <td><a href="{{ route('submit')}}">編集</a></td> <td><a>削除</a></td> </tr> </tbody> </table> </div> @endsection
submit.blade.php
@extends('layouts.app') @section('css') <style> header { height: 50px; background-color: #000; padding-left: 20px; font-size: large; color: #ddd; } .title { position: absolute; top: 10px; } .container { margin-top: 40px; } </style> @endsection @section('content') <form> <div class="form-group"> <label for="title">タイトル</label> <input type="text" class="form-control" id="title" name="title"> </div> <div class="form-group"> <label for="content">内容</label> <input type="text" class="form-control" id="content" name="content"> </div> <a href="{{ route('home')}}" class="btn btn-primary">戻る</a> <button type="submit" class="btn btn-success">追加</button> </form> @endsection
web.php
<?php use Illuminate\Support\Facades\Route; use App\Http\Controllers\MemoController; /* |-------------------------------------------------------------------------- | Web Routes |-------------------------------------------------------------------------- | | Here is where you can register web routes for your application. These | routes are loaded by the RouteServiceProvider within a group which | contains the "web" middleware group. Now create something great! | */ Route::get('blade', function () { return view('home',); }); Route::get('blade', function () { return view('submit'); }); Route::get('/', function () { return view('welcome'); }); // 第一引数に相対パス、第二引数に関数を指定する Route::get('/home', [App\Http\Controllers\MemoController::class,'showHome'])->name('home'); Route::get('/submit', [App\Http\Controllers\MemoController::class,'showSubmit'])->name('submit'); // Route::get('/home', [App\Http\Controllers\MemoController::class,'showHome']); // // Route::get('/submit', [App\Http\Controllers\MemoController::class,'showSubmit']);
MemoController.php
<?php namespace App\Http\Controllers; use Illuminate\Http\Request; class MemoController extends Controller { // home.blade.phpを表示 public function showHome() { return view('home'); } // submit.blade.phpを表示 public function showSubmit() { return view('submit'); } }
https://readouble.com/laravel/8.x/ja/blade.htmlここのサイトを見てテンプレートの読み込みとか確認したのですが、自分のレベルだと解決できません。
・試したことはコメントアウトしたところと
Route::get('blade', function () { return view('home',); }); Route::get('blade', function () { return view('submit'); });
これを書いたことです。
(Laravel8.24.0)
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。