Support the ongoing development of Laravel.io →
Database Eloquent
Last updated 2 years ago.
0
public function messages_from()
{
    return $this->hasMany('Message','from_id');
}
public function messages_to()
{
    return $this->hasMany('Message','to_id');

and

public function from()
{
    return $this->belongsTo('User','from_id');
}
public function to()
{
    return $this->belongsTo('User','to_id');
}

I think these should be fine.

and also use only id for users table, not user_id

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

rahafrouz rahafrouz Joined 6 Sep 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.