スニーカの投稿サイトを作っています。
投稿の詳細ページの作成でTrying to get property 'name' of non-object オブジェクトがないというエラーがかえってきます。
しかしどこのコードが間違っているのかわかりません。
ご教授うお願いいたします。
ファイル名 show.blade.php <body> @extends('layouts.app') @section('content') @if($post !== '') <div class="item-detail"> <div class="item-detail-contents"> <h1 class="item-detail-name">アイテム名</h1> <div class="item-detail-main clearfix"> <div class="item-detail-photo"> <img> </div> <table class="item-detail-table"> <tbody> <tr> <th>投稿者</th> <td> <a class="item-detail-username">ユザー名</a> </td> </tr> <tr> <th>商品名</th> <td> <a class="item-detail-category">{{ $post->name }}</a> </td> </tr> <tr> <th>ブランド</th> <td> {{ $post->brand }} </td> </tr> </tbody> </table> </div> <div class="item-detail-price-box"> <span class="item-detail-price">値段</span> <span class="item-detail-tax">(税込)</span> </div> </div> </div> @endif @endsection </body>
ファイル名PostController.php public function show($id){ $post = Post::find($id); return view('posts.show',['post' => $post]); }
ファイル名web.php Route::get("/","PostController@index"); Route::get('post/new', 'PostController@new'); Route::post('post/create', 'PostController@create')->name('post.create'); // 保存 Route::get('post/create', 'PostController@create')->name('post.create'); // 作成 Route::get('post/{post_id}', 'PostController@show')->name('post.show');
回答1件
あなたの回答
tips
プレビュー