Home > Blockchain >  Attempt to read property "created_at" on null
Attempt to read property "created_at" on null

Time:02-03

I need to output the creation date, but sometimes there may not be a date, for this I did in blade.php @forelse, but it doesn't help

Controller

        $dataBumps[] = DB::table('server_user_likes')
            ->where('server_id', $server->id)
            ->orderBy('created_at', 'DESC')
            ->first();

blade.php

    @forelse ($dataBumps as $dataBump)
        {{$dataBump->created_at}}
    @empty
    -
    @endforelse

CodePudding user response:

You are storing also null values into the array.

You can try to dd($dataBumps); to debug it and add a check in your blade file. A simple example

@forelse ($dataBumps as $dataBump)
@if ($dataBump !== null)
    {{$dataBump->created_at}}
@else
    -
@endif

@empty - @endforelse

  • Related