Page Controller $Sport_Post = AppPost::All()->Where('category_id','=',3)->first(); $Sport_Posts = AppPost::All()->Where('category_id','=',3)->skip(1); return view('welcome', compact('Sport_Post','Sport_Posts')); Code of page @forelse($Sport_Post as $post) <div id="content-number-1" class="col-12 col-md-8 col-lg-8 home-post1 content-number-1"> <div class=""><img class="content-one-img content-img-chapter" src="{{$post->image}}"></div> <div class="content-text-img p-3"><p><a class="m-0 underImage aTagsHover" style="font-size: 20px" href="/inside/{{$post->id}}">{{$post->title}}</a><br><span class="date-font"><i class="fa fa-clock-o" aria-hidden="true"></i>{{$post->created_at}}</span><span class="underBusiness"><br>{{$post->short_desc}}</span></p></div> </div> @empty <div id="content-number-1" class="col-12 col-md-8 col-lg-8 home-post1 content-number-1"> <div class="content-one-img content-img-chapter"></div> <div class="content-text-img p-3"><p><a class="m-0 underImage aTagsHover" style="font-size: 20px" href="#">No post</a><br><span class="date-font"><i class="fa fa-clock-o" aria-hidden="true"></i>No time</span><span class="underBusiness"><br>No post</span></p></div> </div> @endforelse
The error starts in src=”{{$post->image}}”>; What’s wrong ? How to fix it
Advertisement
Answer
modify your code like below
in controller
$Sport_Post = AppPost::Where('category_id','=',3)->first();
in blade file no need of for loop because $Sport_Post is a single object not a collection so modify blade code as below:
@if(isset($Sport_Post)) <div id="content-number-1" class="col-12 col-md-8 col-lg-8 home-post1 content-number-1"> <div class=""><img class="content-one-img content-img-chapter" src="{{$Sport_Post->image}}"></div> <div class="content-text-img p-3"><p><a class="m-0 underImage aTagsHover" style="font-size: 20px" href="/inside/{{$Sport_Post->id}}">{{$Sport_Post->title}}</a><br><span class="date-font"><i class="fa fa-clock-o" aria-hidden="true"></i>{{$Sport_Post->created_at}}</span><span class="underBusiness"><br>{{$Sport_Post->short_desc}}</span></p></div> </div> @else <div id="content-number-1" class="col-12 col-md-8 col-lg-8 home-post1 content-number-1"> <div class="content-one-img content-img-chapter"></div> <div class="content-text-img p-3"><p><a class="m-0 underImage aTagsHover" style="font-size: 20px" href="#">No post</a><br><span class="date-font"><i class="fa fa-clock-o" aria-hidden="true"></i>No time</span><span class="underBusiness"><br>No post</span></p></div> </div> @endif