这是项目迁移
Schema::create('projects', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->string('start_date');
$table->string('end_date');
$table->string('con');
$table->timestamps();
});
这是时间表
Schema::create('timesheets', function (Blueprint $table) {
$table->increments('id');
$table->string('user_id');
$table->string('project_id');
$table->string('day');
$table->string('month');
$table->string('year');
$table->string('jalali');
$table->string('timesheet_h');
$table->string('timesheet_m');
$table->timestamps();
});
用户迁移
Schema::create('users', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->string('mobile');
$table->string('salary_base');
$table->string('salary_base_h');
$table->string('start_contract');
$table->string('end_contract');
$table->string('start_insurance');
$table->string('end_insurance')->nullable();
$table->string('first_salary');
$table->string('date_birth');
$table->string('melli_code');
$table->string('s_number');
$table->string('nda');
$table->string('work_rules');
$table->string('end_work')->nullable();
$table->string('password');
$table->rememberToken();
$table->timestamps();
});
这是我的项目模型
public function timesheets()
{
return $this->hasMany(timesheet::class,'project_id');
}
这是我的时间表模型:
public function projects()
{
return $this->belongsTo(project::class,'project_id');
}
public function users()
{
return $this->belongsTo(User::class,'user_id','id');
}
这是我的用户模型
public function project_peoples()
{
return $this->hasMany('App\project_people');
}
public function timesheets()
{
return $this->belongsTo(timesheet::class);
}
public function projects()
{
return $this->belongsTo(project::class);
}
现在我从项目返回我的查询
public function allProject()
{
$projects=project::with(['timesheets','users'])->get();
return $projects;
}
这是可以的,但用户id用户在时间表。用户id和我不能得到它的时间表和得到它
此控制器按时间表中的项目id返回项目和时间表,但时间表中的用户id我不知道如何将其放入系统
2条答案
按热度按时间bfrts1fy1#
这是我的回报我有2个用户,但重复我的2个用户:(
8ehkhllq2#
使用点语法加载嵌套关系: