Support the ongoing development of Laravel.io →
posted 4 years ago
Last updated 1 year ago.
0

This ussualy happens when you are trying to access a function on an inexisting object. For example, if you have in your code:

{{ $student->math_class->created_at->format('M d, Y') }}

... but $student has'nt a math_class relationship, then created_at is null (not a Carbon date object) and you can't use the function format on that inexisting object.

In blade, I use the next ternary operator to prevent crash:

{{ $student->math_class ? $student->math_class->created_at->format('M d, Y') : '--' }} 
Last updated 4 years ago.
0

Thank you Rafa, I tried to edit my codes but sadly it's giving me the same error.

0

Check your database. Probably the date field is null, or it has an invalid value like '0000-00-00'. If you can share your portion of code, it helps a lot.

0
<div class="panel panel-default"> <div class="panel-heading"> <h4 class="panel-title"><?php echo e($evaluation->notice->name); ?></h4> </div>
<table class="table table-bordered table-condensed">
    <tr>
        <th class="col-xs-2"><?php echo e(trans('evaluations.attributes.notice_number')); ?></th>
        <td class="col-xs-2"><?php echo e($evaluation->notice->number); ?></td>
        <th class="col-xs-2"><?php echo e(trans('evaluations.attributes.notice_type')); ?></th>
        <td class="col-xs-2"><?php echo e($evaluation->type ? $evaluation->type->name : blank_icon(nil)); ?></td>
        <th class="col-xs-2"><?php echo e(trans('evaluations.attributes.organization')); ?></th>
        <td class="col-xs-2"><?php echo e($evaluation->notice->organization->name); ?></td>
    </tr>
    <tr>
        <th class="col-xs-2"><?php echo e(trans('evaluations.attributes.submission')); ?></th>
        <td class="col-xs-2"><?php echo e($evaluation->submission->number); ?></td>
        <th class="col-xs-2"><?php echo e(trans('evaluations.attributes.submitted_at')); ?></th>
        <td class="col-xs-2"><?php echo e($evaluation->submission ? $evaluation->submission->submitted_at->format('DD/MM/YYYY') : 'HH:mm:ss'); ?></td>
        <th class="col-xs-2"><?php echo e(trans('evaluations.attributes.type')); ?></th>
        <td class="col-xs-2"><?php echo e($evaluation->type ? $evaluation->type->name : blank_icon(nil)); ?></td>
    </tr>
</table>
</div>
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.