laravel怎样关联插入数据?
phpcn_u1582
phpcn_u1582 2017-05-16 16:55:17
0
1
827

悬而未决:

表Users
表UserProfiles

Users对UserProfiles是hasOne关系

  public function hasOneProfile(){

    return $this->hasOne('App\UserProfile','user_id','id');

  }

UserProfiles对Users是belongsTo关系

  public function belongsToUser(){

    return $this->belongsTo('User','user_id','id');

  }

当一个新的 $user = new Users(); 被创建时

如何直接写 $user 的属性,可以达到 save() 的时候可以把 UserProfile 一并直接创建呢?

比如说:
只给 UserProfile 指定一个属性 sex=1 然后怎么能直接当成新的 User 和 UserProfile 一并 Create 了……

phpcn_u1582
phpcn_u1582

全員に返信(1)
人気のチュートリアル
詳細>
最新のダウンロード
詳細>
ウェブエフェクト
公式サイト
サイト素材
フロントエンドテンプレート
私たちについて 免責事項 Sitemap
PHP中国語ウェブサイト:福祉オンライン PHP トレーニング,PHP 学習者の迅速な成長を支援します!