1
I’m trying to get an ID from the database, but I get the following error:
Trying to get Property 'id' of non-object...
My code:
if($provider == null) {
$provider = array(
'provider' => $p->provider,
'items' => array($p),
'object' => User::find($p->provider),
'month' => array($order->id => $months)
);
$providers[] = $provider;
}
The result will show me a filter for a report:
<?php $__currentLoopData = $providers; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $provider): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
<?php if($provider['object']->id != 3104): ?>
<option value="<?php echo e($provider['object']->id); ?>" provider="<?php echo e(json_encode($provider),true); ?>"><?php echo e($provider['object']->name); ?></option>
<?php else: ?>
<option value="<?php echo e($provider['object']->id); ?>" provider="<?php echo e(json_encode($provider),true); ?>" class="d-none"><?php echo e($provider['object']->name); ?></option>
<?php endif; ?>
<?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
Error occurs on line <?php if($provider['object']->id != 3104): ?>
I use PHP 7.2.
And what is
$order
?– Woss
It is a variable that receives requests.
– Guilherme Andrade
Okay. And what kind is she? She owns the field
id
? What is the return ofvar_dump($order)
?– Woss
On what line exactly are you making this mistake? Why might you also be giving in
<?php if($provider['object']->id != 3104): ?>
if$provider['object']
by chance isnull
you’ll never find aid
there, and in your'object' => User::find($p->provider)
there is no guarantee q'object'
it won’t be null– Erlon Charles
It is of the null type, set when necessary. Yes it receives the id of the bank, which will filter the providers.
– Guilherme Andrade
The mistake is making
<?php if($provider['object']->id != 3104): ?>
, but before it was working normally.– Guilherme Andrade
@Erloncharles And how could I make mine
object
never came backnull
of my search in the bank? I would attribute it directly toid
?– Guilherme Andrade