1

我有两张桌子:一张 forUser和一张 for Profile。我试图弄清楚如何在用户注册时更新配置文件表。

这是我的UserProfile模型类:

    <?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');
    }
}
4

1 回答 1

0

您可以尝试事件: http: //laravel.com/docs/events

创建一个 On.user.create 事件并构建一个监听器来做你需要的事情。

我不确定,但您可以尝试将更新配置文件的代码放在用户构造函数中。

于 2013-06-06T22:28:41.960 回答