Php Laravel多对多关系用户轮班

Php Laravel多对多关系用户轮班,php,laravel,eloquent,many-to-many,relationship,Php,Laravel,Eloquent,Many To Many,Relationship,我正试图找到今天轮班的用户。我在用户和班次模型之间有一个多对多关系,有一个称为User\u shifts的数据透视表 我的用户模型: /** * Get the users shifts */ public function shift() { return $this->belongsToMany('App\Shift', 'user_shifts', 'user_id', 'shift_id'); } 我的轮班模式 /** * The shift can have ma

我正试图找到今天轮班的用户。我在用户和班次模型之间有一个多对多关系,有一个称为User\u shifts的数据透视表

我的用户模型:

/**
 * Get the users shifts
 */
public function shift()
{
    return $this->belongsToMany('App\Shift', 'user_shifts', 'user_id', 'shift_id');
}
我的轮班模式

/**
 * The shift can have many users
 */
public function users()
{
    return $this->belongsToMany('App\User', 'user_shifts', 'shift_id', 'user_id')->withPivot('start_time', 'end_time');;
}
在我的控制器中,我想我可以做如下事情:

$shift = Shift::all()->where('date', date('Y-m-d'));

$users = User::all()->where('shift_id', $shift);

return $users;
但这是返回空值。任何帮助都将不胜感激

如果有关系,我的数据库模式是:

Schema::create('shifts', function (Blueprint $table) {
    $table->increments('id');
    $table->date('date');
    $table->boolean('weekend');
});

Schema::create('user_shifts', function (Blueprint $table) {
    $table->increments('id');
    $table->integer('shift_id');
    $table->integer('user_id');
    $table->time('start_time');
    $table->time('end_time');
});

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

我认为
return$this->belongtomany('App\Shift','user\u shifts','Shift\u id','user\u id')我认为
返回$this->belongTomany('App\Shift','user\u Shift','Shift\u id','user\u id')