jeudi 4 février 2016

How to create subcollection using Laravel 5 and mongodb

First of all I'm new to laravel mongodb collection using jenssegers in laravel 5.0 . I would like to form a collection inside sub collection like below

    {
  "Uid": 1112,
  "AccountNo": 7620424,
  "Party": {
    "LanguageCode": "en",
    "Type": "individual",
    "Contact": [
      {
        "id" : It will be mongo object id How to create?
        "Type": "default",
        "Person": {
          "FullName": "Test Test"
        },
         {
        "id" : It will be mongo object id How to create?
        "Type": "default",
        "Person": {
          "FullName": "Test Test"
        },
        "MessagingMedium": [
          {
            "Id": It will be mongo object id How to create?
            "Scheme": "mailto",
            "URI": "demo1dd122@gmail.com",
            "Status": "awaiting.registration"
          },
          {
            "Id": It will be mongo object id How to create?
            "Scheme": "mailto",
            "URI": "demo1dd122@gmail.com",
            "Status": "awaiting.registration"
          }
        ]
      }
    ]
  },
}

I have userprofile model

use Jenssegers\Mongodb\Model as Eloquent;

class UserProfile extends Eloquent  {

    protected $table = 'user_profile';
}

use Jenssegers\Mongodb\Model as Eloquent;

class Contact extends Eloquent  {

    protected $table = 'contact';
}

I have trying to create user profile after trying to add contacts subcollection to that created userprofile collection like below

$user = UserProfile::create(array('Uid' => $uId, 'AccountNo' => $accNo));
$card = Contact::create(['id' => 123]); //contact mongodb Eloquent
$card->userprofile()->save($card); 

But its not working and the collection is not creating

Is that correct and i dont know abount hasmany, embedsmany colleciton

Anyone help me out



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/1SNw1XI
via IFTTT

Aucun commentaire:

Enregistrer un commentaire