내 코드에 무엇이 잘못 되었나요? 여기에 내가 때문에 비 개체의 속성을 얻으려고 노력의 $에 datav의 라인 오류가 발생했습니다L5 - 오류 : 비 - 객체 (이상한 케이스)의 속성을 얻으려고 시도
$datax = \App\AccountsScore::where('account_id', $account_id)
->where('score_id', $score->id)
->first();
$datav = \App\AccountsScoreHistory::where(
'account_score_id', $datax->id
)->get();
코드입니다. 그러나 아래 $ datax 또는 $ datax-> id 인쇄 할 때 결과입니다.
-는 DATAX에게 여기
24467
ID
이Whoops, looks like something went wrong.
1/1 ErrorException in HomeController.php line 154: Trying to get property of non-object
여기 내 HomeController.php의 오류 메시지의 $ 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] =>
)
(166 라인 145) $
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;
}
이 코드에 대해 좌절감을 느끼니 도움을 주셨습니다.
정확한 오류 메시지를 게시 할 수 있습니까? '-> get()'메서드를 호출 할 때'non object'라는 에러 메시지가 나올 수 있습니까? – codedge
뭐, 뭔가 잘못 된 것 같습니다. 1/1 HomeController.php의 ErrorException 154 : 비 객체의 속성을 얻으려고 시도 중 –
원래 게시물을 편집하고 거기에 오류 메시지를 입력하십시오. 또한 HomeComtroller.php를 추가하면 무슨 일이 일어나는지 볼 수 있습니다. – codedge