skip to Main Content

When I try to display the contents of the date field within a view, I get an error:
Undefined property: stdClass::$show.

$shows = DB::select("SELECT * FROM shows"); ?>
<div class="max-w-2xl p-6 mx-auto ">
    
    @foreach ($shows as $show)
    {{-- @dd($show) --}}
        <div class="mt-6 p-6 bg-sp_white text-dk_brown shadow-sm rounded-lg">
            
            {{ $show->show-date->format('Y-m-d') }}
            {{ $show->venue }} <!-- string --> 
            {{ $show->description }} <!-- string -->
            
        </div>

    @endforeach
</div>

If I remove the date field from the @foreach statement, I get no errors and the string fields are displayed. Also, if I dd($show), I successfully get all expected results.

2

Answers


  1. Chosen as BEST ANSWER

    I reworded the select statement as follows and it works:

    $shows = DB::table('shows')->where('showDate' , '>=' , now()->toDateTimeString())->orderby('showDate', 'asc')->get();
    

  2. Try this

    @foreach ($shows as $show)
        {{-- @dd($show) --}}
            <div class="mt-6 p-6 bg-sp_white text-dk_brown shadow-sm rounded-lg">
                {{date('Y-m-d', strtotime($show->show-date))}}
                {{ $show->venue }} <!-- string --> 
                {{ $show->description }} <!-- string -->
            </div>
    @endforeach
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search