Laravel Error: Details blade displays wrong data, displays previous column data

27
May 12, 2022, at 10:20 AM

I have a Details page that displays "short description", "Duration", and "description of tour" from a database.

Problem: Some Data displayed on the blade is from the previous entry in the table

Question: Why would a details blade display data that's from a previous entry?

code snippet for the details.blade.php

page

    @extends('client.layout.app2')
    @section('title')
   Flamingo WIld Life Vacation | {{$itenary->name}}
    @endsection
    @section('content')

    <div id="page_caption" class="hasbg parallax  " style="background-image:url('/header_image/{{$itenary->header_image}}');">
    <div class="single_tour_header_content">
    <div class="standard_wrapper">
    <a href="/header_image/{{$itenary->header_image}}" id="single_tour_gallery_open" class="button fancy-gallery"><span class="ti-camera"></span>View Photos</a>
    <div style="display:none;">
    @foreach($images as $image)
    <a id="single_tour_gallery_image1" href="/itenary_images/{{$image->body_image}}" title="The road to success and the road to failure are almost exactly the same" class="fancy-gallery"></a>

    @endforeach

    </div>

    <div class="single_tour_header_price">
    <div class="single_tour_price">
    {{ $itenary->name }}
    </div>
    </div>
    </div>
    </div>
    </div>
    <!-- Begin content -->
    <div id="page_content_wrapper" class="hasbg ">
    <div class="inner">
    <!-- Begin main content -->
    <div class="inner_wrapper">
    <div class="sidebar_wrapper">
    <div class="sidebar_top"></div>
    <div class="sidebar">
    <div class="content">
    <div class="single_tour_header_price">
    <div class="single_tour_per_person">
     {{$itenary->name}} </div>
    </div>
    <div class="single_tour_booking_wrapper themeborder contact_form7">
    <div role="form" class="wpcf7" id="wpcf7-f142-o1" lang="en-US" dir="ltr">
        <div class="screen-reader-response"></div>
        <form action="#" method="post" class="wpcf7-form" novalidate="novalidate">
            <p>
                <label> Full Name
                    <br />
                    <span class="wpcf7-form-control-wrap your-name"><input type="text" name="your-name" value="" size="40" class="wpcf7-form-control wpcf7-text wpcf7-validates-as-required" aria-required="true" aria-invalid="false" placeholder="John Doe" /></span> </label>
                </p>
                <p>
                    <label> Email Address
                        <br />
                        <span class="wpcf7-form-control-wrap your-email"><input type="email" name="your-email" value="" size="40" class="wpcf7-form-control wpcf7-text wpcf7-email wpcf7-validates-as-required wpcf7-validates-as-email" aria-required="true" aria-invalid="false" placeholder="sample@yourcompany.com" /></span> </label>
                    </p>
                    <p>
                        <label> Phone Number
                            <br />
                            <span class="wpcf7-form-control-wrap tel-729"><input type="tel" name="tel-729" value="" size="40" class="wpcf7-form-control wpcf7-text wpcf7-tel wpcf7-validates-as-required wpcf7-validates-as-tel" aria-required="true" aria-invalid="false" /></span> </label>
                        </p>
                        <p>
                            <label> Tour Date
                                <br />
                                <span class="wpcf7-form-control-wrap menu-419">
                                    <select name="menu-419" class="wpcf7-form-control wpcf7-select wpcf7-validates-as-required" aria-required="true" aria-invalid="false">
                                        <option value="10-18 January 2017">10-18 January 2017</option>
                                        <option value="23-31 January 2017">23-31 January 2017</option>
                                        <option value="7-15 February 2017">7-15 February 2017</option>
                                        <option value="18-26 February 2017">18-26 February 2017</option>
                                    </select>
                                </span>
                            </label>
                        </p>
                        <p>
                            <label> Number of Person
                                <br />
                                <span class="wpcf7-form-control-wrap text-237">
                                    <input type="text" name="text-237" value="" size="40" class="wpcf7-form-control wpcf7-text" aria-invalid="false" placeholder="1 person" />
                                </span>
                            </label>
                            <span class="wpcf7-form-control-wrap dynamictourtitle">
                                <input type="hidden" name="dynamictourtitle" value="Grand Switzerland" size="40" class="wpcf7-form-control wpcf7dtx-dynamictext wpcf7-dynamichidden" aria-invalid="false" />
                            </span>
                            <span class="wpcf7-form-control-wrap dynamictoururl">
                                <input type="hidden" name="dynamictoururl" value="#" size="40" class="wpcf7-form-control wpcf7dtx-dynamictext wpcf7-dynamichidden" aria-invalid="false" />
                            </span>
                        </p>
                        <p>
                            <input type="submit" value="Book This Tour" class="wpcf7-form-control wpcf7-submit" />
                        </p>
                        <div class="wpcf7-response-output wpcf7-display-none"></div>
                    </form>
                </div>
                <div class="single_tour_view_wrapper themeborder">
                    <div class="single_tour_view_desc">
                    This tour&#039;s been viewed&nbsp;544&nbsp;times in the past week </div>
                    <div class="single_tour_view_icon ti-alarm-clock"></div>
                </div>
                <br class="clear" />
            </div>
            <!--  <a id="single_tour_share_button" href="javascript:;" class="button ghost themeborder"><span class="ti-email"></span>Share this tour</a> -->
            <div class="one withsmallpadding ppb_text" style="text-align:left;padding:30px 0 30px 0;">
                <div class="standard_wrapper">
                    <div class="page_content_wrapper">
                        <div class="inner">
                            <div style="margin:auto;width:100%">
                            </p>
                            <h5 class="space">Share "{{$itenary->name}}" Itenary on:</h5>
                            <div class="social_wrapper shortcode light small">
                                <ul>
                                    <li class="facebook"><a target="_blank" title="Facebook" href="#"><i class="fa fa-facebook"></i></a></li>
                                    <li class="twitter"><a target="_blank" title="Twitter" href="https://twitter.com/#"><i class="fa fa-twitter"></i></a></li>
                                    <li class="Whatsapp"><a target="_blank" title="Whatsapp" href="#"><i class="fa fa-whatsapp"></i></a></li>

                                </ul>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <ul class="sidebar_widget">
            <li id="text-3" class="widget widget_text">
                <h2 class="widgettitle">For More Informations</h2>
                <div class="textwidget"><span class="ti-mobile" style="margin-right:10px;"></span>+254722230053
                    <br/>
                    <span class="ti-alarm-clock" style="margin-right:10px;"></span>Mon - Sat 8.00 - 18.00</div>
                </li>
                <li id="grandtour_tour_posts-11" class="widget Grandtour_Tour_Posts">
                    <h2 class="widgettitle"></h2>
                    @foreach($itenaries->take(3) as $itenary)
                    <div class="one gallery1 grid static filterable portfolio_type themeborder" style="background-image:url('/header_image/{{$itenary->header_image}}');">
                        <a class="tour_image" href="#"></a>
                        <div class="portfolio_info_wrapper">
               <!--  <div class="tour_price ">
               $6,000 </div> -->
               <h5>{{$itenary->name}}</h5>
               <div class="tour_attribute_wrapper">
                <div class="tour_attribute_rating">
                    <div class="br-theme-fontawesome-stars-o">
                        <div class="br-widget">
                            <a href="javascript:;" class="br-selected"></a>
                            <a href="javascript:;" class="br-selected"></a>
                            <a href="javascript:;" class="br-selected"></a>
                            <a href="javascript:;" class="br-selected"></a>
                            <a href="javascript:;"></a>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <br class="clear" />
    @endforeach
    </li>
    </ul>
    <div class="single_tour_users_online_wrapper themeborder">
    <div class="single_tour_users_online_icon">
    <span class="ti-info-alt"></span>
    </div>
    <div class="single_tour_users_online_content">
    <strong>131</strong> traveler(s) are considering our tours right now! </div>
    </div>
    </div>
    </div>
    <br class="clear" />
    <div class="sidebar_bottom"></div>
    </div>
    <div class="sidebar_content ">
    <h1>{{$itenary->name}}</h1>
    <div class="single_tour_attribute_wrapper themeborder ">
    <div class="one_fourth">
    <div class="tour_attribute_icon ti-time"></div>
    <div class="tour_attribute_content">
    {{$itenary->duration}} </div>
    </div>
    <div class="one_fourth">
    <div class="tour_attribute_icon ti-id-badge"></div>
    <div class="tour_attribute_content">
    Age 12+ </div>
    </div>
    <div class="one_fourth">
    <div class="tour_attribute_icon ti-calendar"></div>
    <div class="tour_attribute_content">
    Sep,&nbsp;Oct,&nbsp;Nov,&nbsp;Dec </div>
    </div>
    <div class="one_fourth last">
    <div class="tour_attribute_icon ti-user"></div>
    <div class="tour_attribute_content">
    Availability 50 </div>
    </div>
    </div>
    <br class="clear" />
    <p>{!! $itenary->short_description !!}.</p>
    <div class="single_tour_content">
    <p class="p1"> {!! $itenary->description_of_tour !!}.</p>
    </div>
    <div class="fullwidth_comment_wrapper sidebar">
    <div>

    <div class="comment" id="comment-20">

    <div class="right ">

    <a rel='nofollow' class='comment-reply-link' href='#' aria-label='Reply to Jack Dawson'>Reply</a>
    <div class="comment_text" />

    </div>
    </div>
    <br class="clear" />
    </li>
    <!-- #comment-## -->

    <br class="clear" />
    </li>
    <!-- #comment-## -->

    <br class="clear" />
    </li>
    <!-- #comment-## -->

    </div>
    <br class="clear" />
    </li>
    <!-- #comment-## -->
    </div>

    </div>
    </div>
    </div>
    </div>
    <!-- End main content -->
    <br class="clear"/>
    <div class="tour_related">
    <h3 class="sub_title">Similar Tours</h3>
    <div id="portfolio_filter_wrapper" class="gallery classic three_cols portfolio-content section content clearfix" data-columns="3">
    @foreach($itenaries->take(3)  as $itenary)
    <div class="element grid classic3_cols">
    <div class="one_third gallery3 classic static filterable portfolio_type themeborder" data-id="post-171">
    <a class="tour_image" href="#">
    <img src="{{asset('header_image/'.$itenary->header_image)}}" alt="{{$itenary->name}}l" />
    <!--  <div class="tour_price has_discount">
    <span class="normal_price">
    $6,000
    </span> $5,900
    </div> -->
    </a>
    <div class="portfolio_info_wrapper">
    <a class="tour_link" href="{{ route('itenaries.show',$itenary->slug) }}"><h4>{{$itenary->name}}</h4></a>
    <div class="tour_excerpt">
    <p>{{$itenary->itenary_category}}</p>
    </div>
    <div class="tour_attribute_wrapper">
    <div class="tour_attribute_rating">
    <div class="br-theme-fontawesome-stars-o">
    <div class="br-widget">
    <a href="javascript:;" class="br-selected"></a>
    <a href="javascript:;" class="br-selected"></a>
    <a href="javascript:;" class="br-selected"></a>
    <a href="javascript:;" class="br-selected"></a>
    <a href="javascript:;"></a>
    </div>
    </div>
    <div class="tour_attribute_rating_count">
    4&nbsp; reviews </div>
    </div>
    <div class="tour_attribute_days">
    <span class="ti-time"></span> {{$itenary->duration}} </div>
    </div>
    <br class="clear" />
    </div>
    </div>
    </div>
    @endforeach
    </div>
    </div>
    </div>
    <br class="clear" />
    </div>
    @endsection

Itenary Controller


    public function show($slug){
    
            $itenary=Itenary::where('slug', $slug)->firstOrFail();
            $images=$itenary->itenary_images;
             $itenaries=Itenary::get();
    
    
    // dd($images);
            return view('client.itenary.details')->with('itenary', $itenary)->with('images', $images)->with('itenaries', $itenaries);
        }

I have done php artisan optimize, I have cleared the cache. but no changes

Answer 1

There is a @foreach($itenaries->take(3) as $itenary) in the view where you overwrite the $itenary variable that you fill in the controller.

READ ALSO
File Download via API using Guzzle

File Download via API using Guzzle

I'm still on the learning slopes with Guzzle, but am stumped with this issue

39
How would i curl a hls using php

How would i curl a hls using php

I want to curl a HLS that returns forbidden in the browser with Php so in another words i want to return the contents of say

73
Complex query between 4 tables in Laravel

Complex query between 4 tables in Laravel

I have 4 tables : users , user_store_info , user_store_options , product_supplies

70
how to add data to json file flutter?

how to add data to json file flutter?

i have a datajson file like this in which i am getting a list of data i want to add another parameter{p_quantity} to this json file

54