$comments = comments::where('post_id', '=', $post_id)->first();
On a side note... Models are generally singular and start with an uppercase letter, ie Comment
$comments = Comment::where('post_id', '=', $post_id)->first();
pogachar said:
$comments = comments::where('post_id', '=', $post_id)->first();
On a side note... Models are generally singular and start with an uppercase letter, ie Comment
$comments = Comment::where('post_id', '=', $post_id)->first();
This returns a null value. Also:
<?php
class Comments extends Eloquent {
protected $table = 'comments';
}
DrPrez said:
Do you have relations between posts and comments models?
In that case
class Post extends Eloquent {
public function comments()
{
return $this->hasMany('Comment');
}
}
class Comment extends Eloquent {
public function post()
{
return $this->belongsTo('Post');
}
}
$comments = Post::find($id)->comments;
pogachar said:
DrPrez said:
Do you have relations between posts and comments models?
In that case
class Post extends Eloquent { public function comments() { return $this->hasMany('Comment'); } } class Comment extends Eloquent { public function post() { return $this->belongsTo('Post'); } }
$comments = Post::find($id)->comments;
Thank you, could you explain the hasMany and belongsTo function to me, because right now I understand that they link together somehow, but if you could tell me how it works I would have a much better understanding. I did read the documentation on it, but it didn't really cover how it works.
Look for database design tutorials/books. They will explain much better than I could.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community