我有一个像这样设置的模型,
class Project extends Eloquent {
public function projectmanager(){
return $this->belongsTo('User', 'project_manager');
}
}
我在项目数据库中的一行上运行编辑,而project_manager列返回项目经理用户的ID,我想要该用户的详细信息 - 我正在保存我的数据,< / p>
$project = Project::where('id', '=', $id)->get();
$project->name = Input::get('name');
$project->description = Input::get('description');
$project->total_cost = Input::get('cost');
$project->start_date = Input::get('start_date');
$project->finish_date= Input::get('finish_date');
$project->run_number_days = $this->get_days_between_two_dates(Input::get('start_date'), Input::get('finish_date'));
$project->num_days_from_year_start = $this->get_days_between_two_dates("2014-01-01", Input::get('start_date'));
$project->project_manager = Input::get('project_manager');
$project->save();
return $project
不是返回我实际保存的内容,而是如何返回行以及所有关系数据?
答案 0 :(得分:0)
您可以动态加载相关模型
$project->save();
$project->load('projectmanager');
return $project;