I did relationships between different models all the time but for some reason I can't get this one to work. I tried everything I can find on Google but no luck.
I want to create a relation between Comment and User models. Any user can make many comments and I need to use email address of the commenter.
Basically, this:
$comments->user->email
My database looks like this:
userdata
--- id
--- username
--- email
comments
--- id
--- username
--- comment
userdata.username and comments.username should be related to eachother.
I pass the data to views like this:
Comment::with('user')->where('on', $news->id)->orderBy('id', 'DESC')->take(10)->get()
No matter what I try, I can't get it to work. Relations are not created. Maybe I came across a strange laravel bug?
Those are my models: (I write the default ones since I messed them up so much trying different approaches)
class Comment extends Eloquent {
public static $key = 'id';
protected $table = 'comments';
public $timestamps = true;
}
class User extends Eloquent implements UserInterface, RemindableInterface {
protected $table = 'userdata';
public $timestamps = false;
//It contains necessary imports and methods, I cutted them off for stackoverflow
}
Does anybody have an idea how can I solve this?