简体   繁体   中英

Laravel 5.3 : 2 same relationships for 2 same Tables

i need help for make something : I have 2 table :

- Users
----------
id_user


 - Sports
----------
id_sport

title_sport

User can practice 1 or more sport.

User can search user who practice 1 or more sport.

Can you help me please for the model User?

Can i use something like this ?

namespace App;

use Illuminate\Database\Eloquent\Model;

class User extends Model
{

    public function pratice()
    {
        return $this->belongsToMany('App\Sport');
    }
   public function search_user()
    {
        return $this->belongsToMany('App\Sport');
    }
}

with 2 pivots table.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM