LoginSignup
ao711
@ao711

Are you sure you want to delete the question?

Leaving a resolved question undeleted may help others!

Laravel 編集

Q&AClosed

解決したいこと

Laravelで商品管理システムをつくっています。
詳細画面の作成をしており、localhostで開くと詳細画面表示でなくエラーが面が出てきます。
色々なサイトを見ながら進めているのですが、どこを治す出来なのかわかりません。
解決法を教えてください。

発生している問題・エラー

Property [id] does not exist on this collection instance.

例)

///編集ボタンcontroller
  public function Edit($id){
    $productes_model= new Productes();
    $productes = $productes_model->Edit($id);
    return view('edit', ['productes' => $productes]);
  }

または、問題・エラーが起きている画像をここにドラッグアンドドロップ

該当するソースコード

@extends('app')

@section('title')

@section('content')
    <div class="container">

        <div class="row justify-content-center">
         <link href="{{ asset('css/app.css') }}" rel="stylesheet">
            <h1>商品情報詳細画面</h1>
            <form action="center" method="post"></form>
                @csrf
            
            <table>
                <tr>
                <div class="form-group">
                   <td><label for="product_name">ID</label></td>
                   <td><input type="text" class="form-inline"id="id" name="id" placeholder="1"></td>
                </div>
                </tr>
                <tr>
                <div class="form-group">
                    <td><label for="company_name">商品画像</label></td>
                    <td><label><input type="text" class="form-inline"id="img_path" name="img_path" placeholder="画像" ></td>             
                </div>
                </tr>
                <tr>
                <div class="form-group">
                    <td><label for="price">商品名</label></td>
                    <td><input type="text" class="form-inline"id="product_name" name="product_name" placeholder="コーラー"> </td>
                </div>
                </tr>
                <tr>
                <div class="form-group">
                    <td><label for="stock">メーカー</label></td>
                    <td><input type="text" class="form-inline" id="company_name" name="company_name" placeholder="コカコーラー"></td>
                </div>
                </tr>
                <tr>
                <div class="form-group">
                    <td><label for="comment">価格</label></td>
                    <td><lavel><input type="text" class="form-inline"id="price" name="price" placeholder="¥130"></td>
                </div>
                </tr>
                <tr>
                <div class="form-group">
                    <td><label for="img_path">在庫数</label></td>
                    <td><input type="text" class="form-inline"id="stock" name="stock" placeholder="6"></td>
                </div>
                </tr>
                <tr>
                    <div class="form-group">
                    <td><label for="comment">コメント</label></td>
                    <td><input textarea type="text" class="form-inline"id="comment" name="comment" placeholder="〇〇~" ></textarea></td>
                </div>
                </tr>
                <tr>
                <div class="col-sm-offset-2 col-sm-10 text-left">

                <td><a href="{{route('edit,['id'=> $productes->id])}}"><button type="button" class="btn btn-primary">編集</button></a></td>
                <td><button type="button" onClick="history.back()">戻る</button></td>
                </div>
                </tr>
            </table>   
            </form>
        </div>
    </div>
@endsection

    
            

例)

///編集ボタンmodel
    public function Edit($id) {
        $productes= Productes::find($id);
        return $productes;
    }

自分で試したこと

web.phpでも
Route::get('/edit/{id}/', [App\Http\Controllers\ProductesController::class, 'Edit'])->name('edit');//編集追加
とid表示はしてますがエラーが解消されず原因がわかりません。
詳しい方ご教授お願い致します。

0

1Answer

同じ内容の質問でスレッドを乱立するのは閲覧者に迷惑になるのでやめてください。

3

Your answer might help someone💌