public function createAction() { $model = new Evaluation(); $input = Input::all(); $validator = $model->validateInput($input); if ($validator->fails()) { app()->abort(422, $validator->errors()->first()); } $audits = Input::get("auditResult"); foreach ($audits as $audit) { DB::transaction(function () use($model, $audit) { $assertion = new Assertion(["date" => new Carbon(), "mode" => $audit["mode"], "test_id" => $audit["test"]["@id"], "test_type" => $audit["test"]["@type"], "result_type" => $audit["result"]["@type"], "result_outcome" => $audit["result"]["outcome"]]); /** @var Assertor $assertor */ $assertor = Assertor::find(LDModel::getIdFromLdId(Input::get("creator.@id"))); $model->fill(["date" => new Carbon()]); $model->creator()->associate($assertor); $model->save(); /** @var Webpage $subject */ $subject = Webpage::find(LDModel::getIdFromLdId($audit["subject"])); if (!$subject) { app()->abort(422, "Subject not found"); } $assertion->assertor()->associate($assertor); $assertion->subject()->associate($subject); $assertion->evaluation()->associate($model); $assertion->save(); }); } return $this->response($model); }