0
분명히 변수가 테이블에있을 때 변수에 액세스하는 데 문제가 있습니다.Laravel - 정의되지 않은 변수
오류는이 라인에 해당 될
@if ($alert->alert_when == 1)
@endif
Undefined variable: alert_when
이 - 오류입니다.
get()
요청을
dd()
그리고 그것이 가져 오는 것 변수를 볼 수 있습니다
["alert_when"]=> string(1) "1"
전체 dd
인쇄 화면 :
object(Illuminate\Database\Eloquent\Collection)#521 (1) {
["items":protected]=> array(2)
{ [0]=> object(Criteria)#492 (20) { ["connection":protected]=> NULL
["table":protected]=> NULL ["primaryKey":protected]=> string(2) "id"
["perPage":protected]=> int(15) ["incrementing"]=> bool(true)
["timestamps"]=> bool(true) ["attributes":protected]=> array(15) {
["id"]=> string(2) "19" ["user_id"]=> string(2) "23"
["alert_when"]=> string(1) "1"
["created_at"]=> string(19) "0000-00-00 00:00:00"
["updated_at"]=> string(19) "0000-00-00 00:00:00" ["deleted_at"]=> NULL }
내가 접근 할 수 있어요 그 행에있는 다른 데이터는 틀림없이 오타가 없습니다!
왜이 오류가 발생합니까? 미리 감사드립니다.
업데이트
@if ($alert['alert_when'] == 1)
는 오류없이 정확한 응답을 반환합니다. 왜 이런 식으로 $alert->name
에 접속할 수 있습니까?
그래서'$ alert'는 객체 또는 배열입니까? 후자의 경우,'$ alert [ 'alert_when'] ' –
을 사용하여 참조 할 수 있습니다. 예를 들어'{{$ alert-> alert_name}}'을 사용하여 행 내의 다른 데이터에 액세스 할 수 있습니다. 이것은 완벽하게 작동합니다. – Ben
당신의 dd 출력은 그것이 배열임을 암시합니다; dd의 전체 출력을 확실하게 표시하십시오 –