Title: Laravel 5.2 - Trying to get property of non-object error on Apache Server
Tags: php;server;laravel-5.2
Question: I know this question has been asked and answered multiple times but none of the previous post answers my question.
I'm running a website with Laravel 5.2 on an Linux server and get the error :
Trying to get property of non-object (View: /mnt/nfs/preprod/greement/htdocs/resources/views/qual_ops/qual_ops_show.blade.php)
It works perfectly well with a certain user with WampServer but doesn't on the server (with the same user). Some users also get the error because they are missing a parameter, I'm aware of that.
I checked the databases and files but the only difference is that the tables need to have a capital letter at the beginning of their names (changes made before so the website can run on the server.
Controller - UserQualOpsController.php :
public function show($id)
$compte = Compt75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0find($id);
$userQualOps = User_qual_ops75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0join('qual_ops', 'qual_ops.id_qual_ops', '=', 'user_qual_ops.id_qual_ops')
-&gt;join('type_qual_ops', 'type_qual_ops.id_type_qual_ops', '=', 'qual_ops.id_type_qual_ops')
-&gt;where('id_compte', $id)
-&gt;orderBy('type_qual_ops.nom', 'asc')
-&gt;orderBy('qual_ops.code_qual_ops', 'asc')
-&gt;orderBy('date_obtention', 'desc')
-&gt;get();
$params = [];
foreach($userQualOps as $userQualOp){
$params[$userQualOp-&gt;id_qual_ops] = Qual_ops_param75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0where(function($query){
$query-&gt;where('id_organisme', 1)
-&gt;orWhere('id_organisme', Auth75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0user()-&gt;id_organisme);
})
-&gt;where('id_qual_ops', $userQualOp-&gt;id_qual_ops)
-&gt;first();
return view('qual_ops/qual_ops_show', [ 'compte' =&gt; $compte,
'userQualOps' =&gt; $userQualOps,
'params' =&gt; $params]);
View - qual_ops_show.blade.php:
@foreach($params as $param)
ERROR HERE -&gt;  @if($param-&gt;id_qual_ops == $userQualOps[$i]-&gt;id_qual_ops)
<?php
$obtentionDate = Carbon75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0parse($userQualOps[$i]-&gt;date_obtention);
switch($param-&gt;premier_seuil_unite){
case 'jour(s)':
$echDatePrem = $obtentionDate-&gt;addDay($param-&gt;premier_seuil);
break;
case 'mois':
$echDatePrem = $obtentionDate-&gt;addMonth($param-&gt;premier_seuil);
break;
}
$obtentionDate = Carbon75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0parse($userQualOps[$i]-&gt;date_obtention);
switch($param-&gt;deuxieme_seuil_unite){
case 'jour(s)':
$echDateDeux = $obtentionDate-&gt;addDay($param-&gt;deuxieme_seuil);
break;
case 'mois':
$echDateDeux = $obtentionDate-&gt;addMonth($param-&gt;deuxieme_seuil);
break;
}
if($echDatePrem-&gt;max(Carbon75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0now()) == $echDatePrem)
$alertNumber = 0;
elseif($echDateDeux-&gt;max(Carbon75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0now()) == $echDateDeux)
$alertNumber = 1;
else
$alertNumber = 2;
?&gt;
@if($alertNumber == 2)
<td class="col-md-2"&gt;{{Carbon75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0parse($userQualOps[$i]-&gt;date_obtention)-&gt;format('d/m/Y')}}<span class="glyphicon glyphicon-alert red-glyphicon float-right"&gt;</span&gt;</td&gt;
@elseif($alertNumber == 1)
<td class="col-md-2"&gt;{{Carbon75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0parse($userQualOps[$i]-&gt;date_obtention)-&gt;format('d/m/Y')}}<span class="glyphicon glyphicon-alert orange-glyphicon float-right"&gt;</span&gt;</td&gt;
@elseif($alertNumber == 0)
<td class="col-md-2"&gt;{{Carbon75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0parse($userQualOps[$i]-&gt;date_obtention)-&gt;format('d/m/Y')}}<span class="glyphicon glyphicon-ok green-glyphicon float-right"&gt;</span&gt;</td&gt;
@endif
@endif
@endforeach
dd($params) :
array:16 [▼
4 =&gt; Qual_ops_param {#592 ▼
#table: "Qual_ops_param"
#primaryKey: "id_qual_ops_param"
#fillable: array:5 [▶]
+timestamps: false
#connection: null
#perPage: 15
+incrementing: true
#attributes: array:8 [▶]
#original: array:8 [▶]
#relations: []
#hidden: []
#visible: []
#appends: []
#guarded: array:1 [▶]
#dates: []
#casts: []
#touches: []
#observables: []
#with: []
#morphClass: null
+exists: true
5 =&gt; Qual_ops_param {#586 ▶}
6 =&gt; Qual_ops_param {#411 ▶}
7 =&gt; Qual_ops_param {#407 ▶}
22 =&gt; Qual_ops_param {#589 ▶}
1 =&gt; Qual_ops_param {#412 ▶}
2 =&gt; Qual_ops_param {#585 ▶}
8 =&gt; Qual_ops_param {#581 ▶}
9 =&gt; Qual_ops_param {#580 ▶}
10 =&gt; Qual_ops_param {#578 ▶}
11 =&gt; Qual_ops_param {#591 ▶}
12 =&gt; Qual_ops_param {#576 ▶}
13 =&gt; Qual_ops_param {#584 ▶}
17 =&gt; Qual_ops_param {#574 ▶}
18 =&gt; Qual_ops_param {#573 ▶}
3 =&gt; Qual_ops_param {#590 ▶}
dd($userQualOps) :
Collection {#593 ▼
#items: array:179 [▼
0 =&gt; User_qual_ops {#594 ▼
#table: "User_qual_ops"
#primaryKey: "id_user_qual_ops"
#fillable: array:5 [ …5]
+timestamps: false
#connection: null
#perPage: 15
+incrementing: true
#attributes: array:10 [ …10]
#original: array:10 [ …10]
#relations: []
#hidden: []
#visible: []
#appends: []
#guarded: array:1 [ …1]
#dates: []
#casts: []
#touches: []
#observables: []
#with: []
#morphClass: null
+exists: true
1 =&gt; User_qual_ops {#595 ▶}
2 =&gt; User_qual_ops {#596 ▶}
I'm just trying to understand why does it work on WampServer (because $params is definitely an array) and how to get this thing working on the Linux server.
I can't run the composer/phpartisan on the server and have to work without it.
Comment: Make checks in your view for `is_object()`. You're assuming that all properties should exist and all indexes should be defined.

Comment: No need, glad you solved it :)

Comment: worked fine on local & preproduction space, i'll try now with the production one. Thanks a lot. Would you know why it worked localy and not on Linux server ?

Comment: also worked on production space. Thanks again :). You can put your comment as an answer if you want too.



{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 0, 'CommentCount': 4, 'ContentLicense': 'CC BY-SA 3.0', 'CreationDate': '2016:00:07/21/16', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<php><server><laravel-5.2>', 'Title': 'Laravel 5.2 - Trying to get property of non-object error on Apache Server', 'ViewCount': 75, 'id': 38501381, 'user_AboutMe': "<pre><code>if($mood!='great'){\n  stop(beingSad);\n  start(beingAwesome);\n  $mood='great';\n}\n</code></pre>\n", 'user_AccountId': 8288681.0, 'user_DisplayName': 'A.Desert', 'user_Reputation': 41.0, 'user_Views': 3.0, 'user_id': 6231070.0}}