How to insert data in laravel?
phpcn_u1582
phpcn_u1582 2017-05-16 16:55:17
0
1
889

Pending:

Table Users
Table UserProfiles

Users has a relationship with UserProfiles

  public function hasOneProfile(){

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

  }

UserProfiles has a belongsTo relationship with Users

  public function belongsToUser(){

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

  }

When a new $user = new Users(); is created

How to directly write the attributes of $user so that when save() is achieved, the UserProfile can be created directly?

For example:
Only specify one attribute for UserProfile sex=1 Then how can you directly create it as a new User and UserProfile together...

phpcn_u1582
phpcn_u1582

reply all(1)
洪涛

Create the user profile before saving. The user profile cannot be saved until it is created successfully.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!