muzafferdede
7 months ago
560
2
Laravel

Newly created model returns only few attributes

Posted 7 months ago by muzafferdede

i am trying to make a new Account using create method with default values in migration but when i try to return the newly created account, only few attributes are returning with the instance.

        $account = Account::create();

            $this->card->activate($account, $this->device->store);
            return Response::success($account));

this returns

{
  "updated_at": "2019-10-16 06:59:46",
  "created_at": "2019-10-16 06:59:46",
  "id": 12
}

if i do this which is what i need as return

$account = Account::create();

$this->card->activate($account, $this->device->store);
return Response::success($account->find($account->id));

then i get

  {
    "id": 12,
    "profile_id": null,
    "membership": "anonymous",
    "tokens": 0,
    "tickets": 0,
    "points": 0,
    "created_at": "2019-10-16 07:04:41",
    "updated_at": "2019-10-16 07:04:41",
  }

all attributes has default value in db so newly created model should have all those default values. I don't know why model instance returns only id and timestamps from create method. am i missing something?

Please sign in or create an account to participate in this conversation.