dimanche 29 septembre 2019

Relationships retrieve user emails

I'm trying to understand how I can join the tables users and teams to members in fact ?

Users Table:

id |   name  |         email          |     password
 1     alain        alain@gmail.com          *****
 2     eric         eric1@gmail.com          *****

Teams Table:

id |     name          
 1      R.O.S    
 2      Stephanois   

Members Table:

id |     user_id  (email)        |    team_id (name)
 1          1                             1
 2          2                             1

DataBase:

public function up()
    {
        Schema::create('users', function (Blueprint $table) {
            $table->increments('id');
            $table->string('name');
            $table->string('email')->unique();
            $table->string('password');
            $table->rememberToken();
            $table->timestamps();
        });
    }

public function up()
    {
        Schema::create('members', function (Blueprint $table) {
            $table->increments('id');
            $table->integer('user_id')->unsigned()->nullable();
            $table->foreign('user_id')->references('id')->on('users');
            $table->integer('team_id')->unsigned()->nullable();
            $table->foreign('team_id')->references('id')->on('teams');
            $table->timestamps();
        });
    }

 public function up()
        {
            Schema::create('teams', function (Blueprint $table) {
                $table->increments('id');
                $table->string('name');
                $table->integer('user_id')->unsigned()->nullable();
                $table->foreign('user_id')->references('id')->on('users');
                $table->timestamps();
            });
        }

User Model:

protected $fillable = [
        'name', 'email', 'password',
    ];

public function team(){
        return $this->hasOne('App\Team', 'user_id', 'id'); ?
    }

public function member(){
        return $this->hasMany(??????????);
    }

Team Model:

protected $fillable = [
        'user_id', 'name'
    ];

public function member(){
        return $this->hasMany('App\Member', 'team_id'); ?
    }

public function user(){
        return $this->belongsTo('App\User', 'id', 'user_id'); ?
    }

Member Model:

protected $fillable = [
        'id', 'user_id', 'team_id'
    ];

public function team(){
    return $this->belongsTo('App\Team', 'team_id');
    }

public function user(){
    return $this->belongsTo('App\User', 'id', 'user_id'); ?
    }

I thank you in advance for your help



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2nJTIKh
via IFTTT

Aucun commentaire:

Enregistrer un commentaire