我有两张桌子:一张 forUser
和一张 for Profile
。我试图弄清楚如何在用户注册时更新配置文件表。
这是我的User
和Profile
模型类:
<?php
use Illuminate\Auth\UserInterface;
use Illuminate\Auth\Reminders\RemindableInterface;
class User extends Eloquent implements UserInterface, RemindableInterface{
protected $fillable = array('fname','lname','email','password','create_at','updated_at');
/**
* The database table used by the model.
*
* @var string
*/
protected $table = 'users';
/**
* The attributes excluded from the model's JSON form.
*
* @var array
*/
protected $hidden = array('password');
/**
* Get the unique identifier for the user.
*
* @return mixed
*/
public function getAuthIdentifier()
{
return $this->getKey();
}
/**
* Get the password for the user.
*
* @return string
*/
public function getAuthPassword()
{
return $this->password;
}
/**
* Get the e-mail address where password reminders are sent.
*
* @return string
*/
public function getReminderEmail()
{
return $this->email;
}
/**
* @method to insert values into database.
*/
public static function create_user($data = array())
{
return User::create($data);
}
/**
*@method to validate a user in the database
*/
public static function validate_creds($data)
{
return Auth::attempt($data);
}
public function profile()
{
return $this->hasOne('Profile');
}
public function post()
{
return $this->hasMany('Post');
}
}
我的个人资料模型:
<?php
class Profile extends Eloquent{
public static function createNewProfile($data)
{
return Profile::create($data);
}
public static function editProfile()
{
//
}
public function user()
{
return $this->belongsTo('User');
}
}