请尝试以下方法:
$gallery_id = 2; // user selected gallery 2 $project = new Project(); $project->title = "new project"; $project->save(); $gallery = Gallery::find($gallery_id); $gallery->project_id = $project->id; $gallery->save();