last day (14 days later) » 

2:45 AM
0
Q: Laravel: Invalid argument supplied for foreach()

VranvsI'm trying to iterate through two relational arrays attached to my ANNOUNCEMENT object (Announcement hasMany comments, hasMany attachments). This is my code which grabs the stuff from the database: $posts = Announcement::with(['comments', 'attachments']) ->take(30)->orderBy('id', 'des...

 
Property [attachments] does not exist on this collection instance.
 
$post[0] on error? anywhere key attachments not exits
 
What does that mean?
 
@foreach ($posts as $post) @if(!isset($post->attachments)) "not exits"; @endif @endforeach
 
But, lots of my posts have NO comments and the loop still works just fine.
 
2:45 AM
can u use this? ->with("comments","attachments")
 
Yes, that syntax is correct but I still receive the same error.
hi
 
hi sry I can not cooperate with you.
 
?
 
attachments exits but
got error
 
yes
Are you Chinese?
 
2:49 AM
japanese
:)
 
Boku wa Niku desu
:)
 
return view("????",["posts"=>$post[0]])

error?
sensei
senpai
anime
return view("????",["post"=>$post[0]])

@foreach ($post->comments as $comment)
//this works perfectly fine.
@endforeach

@foreach ($post->attachments as $file)
// this gives me the error as below.
@endforeach
 
Sorry i'm not sure what you're asking
Don't worry about it, I will try to figure it out myself
Thank you!
 
:(
ty
$post[0] is exist attachemts and comments
confirm one by one
really error on $posts[0] ??
i just go lunch

i hope u resolve this question.I wish I could help you out
 

last day (14 days later) »