0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Laravel9 Missing required parameter for [Route: ○○] [URI: ○○] [Missing parameter: id].が出た時

Posted at

Laravl9にてMissing required parameter for [Route: ○○] [URI: ○○] [Missing parameter: id].が出た時

PHPのフレームワークLaravel9を利用していて、検索機能を作成時にエラーが出たので、エラーログをメモする。

serch.blade.php
{!! Form::open(['url' => 'search', 'method' => 'get']) !!}
    <div class="form-floating mb-3"  style="width: 70%; margin: 2rem auto;">
        <input type="text" class="form-control" name="shop_salon_search" id="floatingInput" placeholder="name@example.com">
        <label for="floatingInput">Salon & Shop Search</label>
    </div>
    <div class="professional_search_body">
        <h1>Category</h1>
        <div class="body-list topic">
            <ul>
                @foreach ($kinds as $kind)
                <li><button type="submit" name="shop_salon_category" value="{{ $kind->name }}" class="btn btn-outline-danger">{{ $kind->name }}</button></li>
                @endforeach
            </ul>
        </div>
    </div>
    {!! Form::close() !!}

検索時にControllerに'search'という名前でデータを受け渡す。

Controllerで処理したものをsearch_result.blade.phpに渡す。
そこでの処理が以下のコードである。

search.blade.php
@foreach ($posts as $post)
        <div class="topic-center">
        <a href="{{ route('salon_detail', ['id'=>$post->salon_id]) }}">
            <div class="topic-vertical">
                <div class="topic-outer">
                    <div class="topic-detail-top">
                        <img src="{{ asset('picture/salons/'.$post->salon_logo) }}" width="60%" alt="No image">
                        <div class="topic-detail-list">
                            @foreach ($post->categories as $category)
                            <p class="topic-detail-list-p-shop shop_list">{{ $category->name }}</p>
                            @endforeach
                        </div>
                    </div>
                </div>
                <p class="body-p2" style='margin: 1rem; font-size: 18px; font-family: Arial; padding: 0;'>{{ $post->salon_name }}</p>
            </div>
        </a>
        </div>
        <?php
         $count++;
        ?>
        @endforeach

ここの受け渡しでエラーがでた。
よくよく確認すると、データベースにないカラムを参照していた。

search_reslut.blade.php
<a href="{{ route('salon_detail', ['id'=>$post->salon_id]) }}">

エラーではsalon_detailに渡すsalon_idがないよというエラーだった。データベースに保存していたカラム名はsalon_idではなく、idだったためエラーが出ていた。

つまり

search_result.blade.php
<a href="{{ route('salon_detail', ['id'=>$post->id]) }}">

これでエラーがなくなった。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?