我想返回经过身份验证的用户的项目,但没有得到任何东西。我知道记录存在于数据库中。
这是我的模型Project:
public function users(){
return $this->hasMany(User::class);
}
这是我的模型User:
public function projects(){
return $this->hasMany(Projet::class,'user_id');
}
这是控制器功能:
public function projetuser(){
$user = User::find(auth()->user()->id);
return $user->projects;
}
这是我的user_projet迁移:
public function up()
{
Schema::create('user_projet', function (Blueprint $table) {
$table->bigIncrements('id');
$table->unsignedBigInteger('projet_id');
$table->foreign('projet_id')->references('id')->on('projets')->onDelete('cascade');
$table->unsignedBigInteger('user_id');
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
$table->string('membre')->nullbale();
$table->timestamps();
});
}
杨__羊羊