public function store(UserRequest $request) { $attributes = $request->all()['data']['attributes']; // add default elements $attributes['activation_code'] = User::generateCode('activation_code'); $attributes['reason'] = 'have not activated your account yet.'; // create the user $user = new User(); foreach ($attributes as $key => $value) { $user->{$key} = $value; } $user->save(); // create the user profile $user->profile()->save(new UserProfile()); $resource = new Item($user, new UserTransformer(), 'users'); return response()->json($this->fractal()->createData($resource)->toArray(), Response::HTTP_CREATED); }