Search code examples
phplaravellaravel-bladelaravel-artisan

Trying to get property 'id' of non-object only in my website


Recently I updated my website and I found this error only in one view, on my localhost works fine, I uploaded it via FTP. I'm going crazy!

[2020-01-30 03:32:39] local.ERROR: Trying to get property 'id' of non-object (View: /home/csinf298/resources/views/addEdit_promotion.blade.php) {"userId":3,"email":"email@email.com.mx","exception":"[object] (ErrorException(code: 0): Trying to get property 'id' of non-object (View: /home/csinf298/resources/views/addEdit_promotion.blade.php) at /home/csinf298/storage/framework/views/a22f101b5a2d4fafaa9530cd13c1077aebc547ce.php:211, ErrorException(code: 0): Trying to get property 'id' of non-object at /home/csinf298/storage/framework/views/a22f101b5a2d4fafaa9530cd13c1077aebc547ce.php:211)

My.blade

$promotion->id

I tried this too

$promotion->['id']

[2020-01-30 03:58:27] local.ERROR: Parse error: syntax error, unexpected '[', expecting identifier (T_STRING) or variable (T_VARIABLE) or '{' or '$' (View: /home/csinf298/resources/views/addEdit_promotion.blade.php) {"userId":3,"email":"carlos.cisneros@csinformatica.com.mx","exception":"[object] (ErrorException(code: 0): Parse error: syntax error, unexpected '[', expecting identifier (T_STRING) or variable (T_VARIABLE) or '{' or '$' (View: /home/csinf298/resources/views/addEdit_promotion.blade.php) at /home/csinf298/storage/framework/views/a22f101b5a2d4fafaa9530cd13c1077aebc547ce.php:176, Symfony\\Component\\Debug\\Exception\\FatalThrowableError(code: 0): Parse error: syntax error, unexpected '[', expecting identifier (T_STRING) or variable (T_VARIABLE) or '{' or '$' at /home/csinf298/storage/framework/views/a22f101b5a2d4fafaa9530cd13c1077aebc547ce.php:176)

Solution

  • First of all, clear the caches with $promotion->id as using the below command.

    php artisan config:cache
    php artisan view:clear
    php artisan route:clear
    

    If you still get the error then use $promotion->userId as I have seen in your error the object contains userId, not an id.