untymage
2 months ago
255
5
Laravel

hasMany on different table ?

Posted 2 months ago by untymage

I have this relation:

user hasMany invites (invites mean another user_id on the users table)

So i have a table with name of user_invites, In this table i wanna determine which user invite which user

columns: user_id and invited

The problem is hasMany doesnt apply $table argument, So how can i implement this in eloquent way ?

public function up()
{
    Schema::create('user_invites', function (Blueprint $table) {
        $table->id();
        $table->foreignId('user_id');
        $table->foreignId('invited');
        
        $table->foreign('user_id')->references('id')->on('users');
        $table->foreign('invited')->references('id')->on('users');
        
    });
}

Please sign in or create an account to participate in this conversation.