0

Here is the Exception Code Code In the Framework/views/profile_settings.blade.php

When my users visit their profile setting the stack trace errors always come up with the exception. Please help me out. Thanks

$('select[name=country]').val('<?php echo e($user->address->country); ?>');
Vickel
  • 7,879
  • 6
  • 35
  • 56
  • I tried change .val to value but I still get same errors – Treasure Uvietobore Mar 23 '21 at 17:38
  • Add change trigger `$('select[name=country]').val('address->country); ?>')->change();` like this `$('select[name=country]').val('Canada')->change();` – STA Mar 23 '21 at 18:02
  • Does this answer your question? [Reference - What does this error mean in PHP?](https://stackoverflow.com/questions/12769982/reference-what-does-this-error-mean-in-php) – Nico Haase Mar 24 '21 at 08:27

3 Answers3

2

Null Safe Operator

If you are using less version of php 8. You can write these type of code

$country = null;
    if ($user !== null) {
            if ($user->address !== null) {
                $country = $user->address->country;
            }
        }

PHP 8 allows you to write this.

$country = $user?->address?->country;

It will work like these

Helpfull Link

1

$user->address is probably returning null. Try something like:

{{ $user->address->country ?? '' }}
P. K. Tharindu
  • 2,565
  • 3
  • 17
  • 34
0

I have an address in my db but in json format, and some times comes without country.

the way I fixed this was making new property to handle this:

 public function getAddressAsStringAttribute()
    {
        if ($this->address == null) return null;
        if (is_object($this->address) && property_exists($this->address, 'country'))
            return $this->address->country;
        else
            return null;
    }

now you can use this new property like:

$('select[name=country]').val('<?php echo e($user->addressAsString); ?>');
OMR
  • 11,736
  • 5
  • 20
  • 35