Advertisement
Guest User

Untitled

a guest
Jan 19th, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. class shGroupReference extends Model {
  2.  
  3. protected $table = 'shGroupReference';
  4. protected $primaryKey = 'groupID';
  5. public $timestamps = false;
  6. protected $fillable = ['referenceCode', 'referenceID', 'groupID'];
  7.  
  8. public function shGroup() {
  9. return $this->belongsTo(\App\Models\shGroup::class, 'groupID', 'groupID');
  10. }
  11. .....
  12.  
  13. class shGroup extends Model {
  14.  
  15. protected $table = 'shGroup';
  16. protected $primaryKey = 'groupID';
  17. public $timestamps = false;
  18. protected $fillable = ['groupID', 'orgID', 'name', 'categoryCode'];
  19.  
  20. public function shGroupReference() {
  21. return $this->hasOne(\App\Models\shGroupReference::class, 'groupID', 'groupID');
  22. }
  23. .....
  24.  
  25.  
  26. $shGroupReference = App\Models\shGroupReference::create(['referenceCode' => 'caughtya', 'referenceID' => 1005]);
  27. $shGroup = App\Models\shGroup::create(['orgID' => 1, 'name' => 'blabla', 'categoryCode' => 'blublu']);
  28. $shGroupReference->shGroup()->associate($shGroup)->save();
  29.  
  30. var_dump(shGroupReference->toArray());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement