Skip to content

Commit

Permalink
#develop. Add illuminat collection object to pass to output
Browse files Browse the repository at this point in the history
  • Loading branch information
arthurkushman committed Aug 17, 2018
1 parent f2c2c9c commit 7b6c0f4
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/extension/BaseController.php
Expand Up @@ -2,10 +2,10 @@

namespace rjapi\extension;

use Illuminate\Database\Eloquent\Collection;
use Illuminate\Http\Request;
use Illuminate\Routing\Route;
use Illuminate\Support\Facades\DB;
use League\Fractal\Resource\Collection;
use rjapi\exceptions\HeadersException;
use rjapi\helpers\Json;
use rjapi\helpers\Request as RequestHelper;
Expand Down Expand Up @@ -38,37 +38,42 @@ public function createBulk(Request $request)
$meta = [];
$json = Json::decode($request->getContent());
$jsonApiAttributes = Json::getBulkAttributes($json);
$collection = new Collection();

try {
$collection = new Collection();
DB::beginTransaction();
foreach ($jsonApiAttributes as $jsonObject) {
// FSM initial state check
if ($this->configOptions->isStateMachine() === true) {
$this->checkFsmCreate($jsonObject);
}

// spell check
if ($this->configOptions->isSpellCheck() === true) {
$meta[] = $this->spellCheck($jsonObject);
}

// fill in model
foreach ($this->props as $k => $v) {
// request fields should match Middleware fields
if (isset($jsonObject[$k])) {
$this->model->$k = $jsonObject[$k];
}
}

// set bit mask
if (true === $this->configOptions->isBitMask()) {
$this->setMaskCreate($jsonObject);
}

$collection->setData($this->model);
$collection->push($this->model);
$this->model->save();

// jwt
if ($this->configOptions->getIsJwtAction() === true) {
$this->createJwtUser(); // !!! model is overridden
}

// set bit mask from model -> response
if (true === $this->configOptions->isBitMask()) {
$this->model = $this->setFlagsCreate();
Expand All @@ -80,8 +85,7 @@ public function createBulk(Request $request)
DB::rollBack();
}

$this->setRelationships($json, $this->model->id);
$resource = Json::getResource($this->middleWare, $collection, $this->entity, false, $meta);
$resource = Json::getResource($this->middleWare, $collection, $this->entity, true, $meta);
Json::outputSerializedData($resource, JSONApiInterface::HTTP_RESPONSE_CODE_CREATED);
}

Expand Down

0 comments on commit 7b6c0f4

Please sign in to comment.