can you guys show me what's wrong with my code? here's the code
$datax = \App\AccountsScore::where('account_id', $account_id)
->where('score_id', $score->id)
->first();
$datav = \App\AccountsScoreHistory::where(
'account_score_id', $datax->id
)->get();
i got error on $datav 's line because of Trying to get property of non-object. however, below is the result when i print $datax or $datax->id.
$datax
App\AccountsScore Object (
[connection:protected] => riskserver
[table:protected] => accounts_score
[primaryKey:protected] => id
[keyType:protected] => int
[perPage:protected] => 15
[incrementing] => 1
[timestamps] => 1
[attributes:protected] => Array (
[id] => 24467
[account_id] => 114
[score_id] => 14
[value] => 8 )
[original:protected] => Array (
[id] => 24467
[account_id] => 114
[score_id] => 14
[value] => 8 )
[relations:protected] => Array ( )
[hidden:protected] => Array ( )
[visible:protected] => Array ( )
[appends:protected] => Array ( )
[fillable:protected] => Array ( )
[guarded:protected] => Array (
[0] => * )
[dates:protected] => Array ( )
[dateFormat:protected] =>
[casts:protected] => Array ( )
[touches:protected] => Array ( )
[observables:protected] => Array ( )
[with:protected] => Array ( )
[morphClass:protected] =>
[exists] => 1
[wasRecentlyCreated] =>
)
$datax->id
24467
here's the error messages
Whoops, looks like something went wrong.
1/1 ErrorException in HomeController.php line 154: Trying to get property of non-object
here's my HomeController.php (Line 145 - 166)
function getTotalScore($name='', $account_id)
{
if(strlen($name) > 0)
{
$score = Score::where('name', $name)->first();
if(!$score) return 0 ;
$score_id = $score->id;
$datax = \App\AccountsScore::where('account_id', $account_id)->where('score_id', $score->id)->first();
/* line 154 */ $datav = \App\AccountsScoreHistory::whereRaw('account_score_id = '.$datax->id)->get();
$countdatas = count($datav);
if($countdatas == null){
$countdatas = 0;
}
return $countdatas;
}
else{
$data = AccountsScore::select(DB::raw('ifnull(sum(value),0) AS total'))->where('account_id', $account_id)->first();
return $data->total;
}
return 0;
}
So frustating about this code, any help appreciated.