laravel 4 insert one to one relationship example -



laravel 4 insert one to one relationship example -

ok can't seem insert work 1 1 relation ship. start models:

class maintenance{ public function tasklist(){ homecoming $this->hasone('app\models\tasklists','maintenance_id','list_id'); } class tasklists{ public function maintenance(){ homecoming $this->belongsto('app\models\maintenance','maintenance_id','list_id'); }

ok, , controller:

$log = new maintenance(); $log->status = $status; $log->save(); $list = tasklists::create(array('title'=>'maintenance log')); $log->tasklist()->save($list);

now here error get:

illuminate \ database \ queryexception sqlstate[23000]: integrity constraint violation: 1048 column 'maintenance_id' cannot null (sql: insert `tasklists` (`title`, `maintenance_id`, `updated_at`, `created_at`) values (maintenance log, , 2014-06-18 18:00:50, 2014-06-18 18:00:50))

so laravel documentation doesn't state way insert 1 1 relationship. question is, how do that? can provide , example.

thanks much!

insert laravel-4 eloquent one-to-one

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -