I never had any problems with Laravel but i ran into something what is really strange.
I have a one to one
relation storing users metadata in a seperate table.
my Controller update looks like this
$val = Validator::make(Input::all(), $rules);
if($val->passes())
{
$this->cur_user->username = Input::get('username');
$this->cur_user->metadata->first_name = Input::get('first_name');
$this->cur_user->metadata->last_name = Input::get('last_name');
$this->cur_user->metadata->gender = Input::get('gender');
$this->cur_user->metadata->location = Input::get('location');
$this->cur_user->email = Input::get('email');
$this->cur_user->metadata->dob = Input::get('dob');
$this->cur_user->metadata->about = Input::get('about');
if ($this->cur_user->save() && $this->cur_user->metadata->save())
{
$data = array('msg' => 'success');
}
Relations
Users Model
class User extends Eloquent implements UserInterface, RemindableInterface {
/**
* 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;
}
public function metadata()
{
return $this->hasOne('metadata');
}
}
Metadata Model
class Metadata extends Eloquent {
public $timestamps = false;
protected $table = "users_metadata";
public function user()
{
return $this->belongsTo('user');
}
}
What is really weird, if i leave the $this->cur_user->metadata->gender = Input::get('gender');
and $this->cur_user->metadata->about = Input::get('about');
in my validation i get the following error
{"error":{"type":"Exception","message":"SQLSTATE[42S22]: Column not found: 1054 Unknown column 'id' in 'where clause' (SQL: update `users_metadata` set `gender` = ?, `about` = ? where `id` is null) (Bindings: array (\n 0 => '1',\n 1 => 'testing one 2 3',\n))","file":"C:\\BitNami\\apache2\\htdocs\\laravel\\vendor\\laravel\\framework\\src\\Illuminate\\Database\\Connection.php","line":555}}
If i comment it out, all fine and works well, checked everything i do not see any strange things.
Could please someone give me a hint? (searched around found some answers but not really for my problem)