Store a newly created resource in storage.

@param  \Illuminate\Http\Request  $request
@return \Illuminate\Http\Response
346469
public function store(Request $request)
    {
    	foreach (array_keys($_POST) as $key)
		{
			if (strpos($key, "user_check_") === 0)
			{
				$component = explode("_", $key);
				$user_id = $component[2];
				
				$user = User::find($user_id);
                if (isset($_POST["user_$user->id"]))
                {
    				$user->roles()->sync($_POST["user_$user->id"]);
                }
                else
                {
                    $user->roles()->sync([]);
                }
			}
		}
		return redirect(url("user_role"))->with('dp_announce', trans('deeppermission.alert.user_role.updated'));
    }
901862
public function store(Request $request)
    {
        try {
            $blockType = $this->blockTypes->save($request);
        } catch (Exception $e) {
            return $this->handleException($e, trans('soda::errors.create', ['object' => trans('soda::terminology.block_type')]));
        }

        return redirect()->route('soda.block-types.edit', $blockType->getKey())->with('success', trans('soda::messages.created', ['object' => trans('soda::terminology.block_type')]));
    }
760414
public function store(Request $request)
    {
        // check if user has permissions to access this link
        if(!User::hasAccess('Categories', 'create')) {
            return $this->noPermission();
        }

        $data = $request->all();
        $structuredData =  $this->generateTitleAndSlug($data['form']);
        $form = $structuredData['form'];
        $errors = $structuredData['errors'];

        // return errors if there are any
        if(count($errors)) {
            return $this->response("From errors", 400, null, false, false, true, $errors);
        }

        // if category is being created
        if(!isset($form['categoryID'])) {
            // Order item
            $catCount = Category::where("postTypeID", $request->postTypeID)->count();
            $order = $catCount+1;
            $categoryModel = new Category();
        }else{
            // if category is being updated
            $categoryModel = Category::find($form['categoryID']);
            if(!$categoryModel) {
                return $this->response("Category doesn't exist", 500);
            }
            $order = $categoryModel->order;
            $oldTitle = $categoryModel->setAutoTranslate(false)->title;
        }

        // parent ID
        $parentID = 0;
        if(isset($form['parent']['categoryID'])) {
            $parentID = $form['parent']['categoryID'];
        }

        // Create Category
        $categoryModel->title = $form['title'];
        $categoryModel->postTypeID = $data['postTypeID'];
        $categoryModel->parentID = ($parentID ? $parentID: null);
        $categoryModel->featuredImageID = $form['featuredImageID'];
        $categoryModel->description = $form['description'];
        $categoryModel->slug = $form['slug'];
        $categoryModel->isVisible = $form['isVisible'];
        $categoryModel->order = $order;
        $categoryModel->createdByUserID = Auth::user()->userID;
        $categoryModel->customFields = $request->customFieldValues;

        // return results
        if ($categoryModel->save()) {
            if(isset($form['categoryID'])) {
                // update label in menu link with the category title
                $this->updateMenuLinkLabel($data['id'], $form['title'], $oldTitle);
            }
            $redirect = $this->redirect($request->redirect, $categoryModel->categoryID, $data['postTypeID']);
            $response = $this->response('Category is saved', 200, $redirect['id'], $redirect['view'], $redirect['url']);
        }else{
            $response = $this->response('Category is not saved. Please try again later!', 500);
        }
        return $response;
    }
1018958
public function store(Request $request)
    {
        $this->authorize('create-comment', Comment::class);
        
        $this->validate($request, [
            'commentable_type' => 'required|string',
            'commentable_id' => 'required|integer|min:1',
            'message' => 'required|string'
        ]);

        $model = $request->commentable_type::findOrFail($request->commentable_id);

        $comment = new Comment;
        $comment->commenter()->associate(auth()->user());
        $comment->commentable()->associate($model);
        $comment->comment = $request->message;
        $comment->save();

        return redirect()->to(url()->previous() . '#comment-' . $comment->id);
    }
1298400
public function store(Request $request)
    {
        $rules = [
            "content" => "required|max:1024",
        ];
        /** @noinspection PhpUndefinedMethodInspection */
        $request->validate($this->addPolymorphicRules($rules, 'noteable', $request->noteableType));
        $note = new Note();
        $note->content = $request->get("content");
        $note->noteable_id = $request->get("noteableId");
        $note->noteable_type = $request->get("noteableType");
        $this->authorize('manage', $note);
        $note->save();
        return fractal($note, new NoteTransformer())
            ->withResourceName('note')
            ->respond();
    }
683672
public function store(Request $request)
    {
        /** @noinspection PhpUndefinedMethodInspection */
        $request->validate([
            'description' => 'max:256',
            'name' => 'required|max:32',
        ]);
        $memberTag = new MemberTag();
        $this->authorize('store', $memberTag);
        $memberTag->team_id = $this->userContext()->team_id;
        if ($request->has('description')) {
            $memberTag->description = $request->description;
        }
        $memberTag->name = $request->name;
        $memberTag->save();
        return fractal($memberTag, new MemberTagTransformer())
            ->withResourceName('memberTag')
            ->respond();
    }
120322
public function store(Request $request)
    {
        try {
            $permission = $this->permissions->save($request);
        } catch (Exception $e) {
            return $this->handleException($e, trans('soda::errors.create', ['object' => 'permission']));
        }

        return redirect()->route('soda.permissions.edit', $permission->getKey())->with('success', trans('soda::messages.created', ['object' => 'permission']));
    }
707292
public function store( Request $request )
    {
        $data = $request->getContent();
        $parser = new \PHPFHIRGenerated\PHPFHIRResponseParser();
        $fhirBundle = $parser->parse( $data );
        if ( is_a( $fhirBundle, '\PHPFHIRGenerated\FHIRResource\FHIRBundle' ) ) {

            // Instansiate the response bundle
            $fhirResponseBundle = new FHIRBundle();

            // Iterate over each entry in the Request Bundle and handle them according to
            // their Request elements
            $entries = $fhirBundle->getEntry();
            foreach ( $entries as $entry ) {

                // First get the proper resource out of the Resource Container
                $resourceContainer = $entry->getResource();
                $publicVars = get_object_vars( $resourceContainer );
                foreach ( $publicVars as $resourceKey => $value ) {
                    if ( $value !== null ) {
                        // This is resource that our Resource Container is holding
                        $resource = $resourceContainer->{$resourceKey};
                        break;
                    }
                }

                // Prepare to build the response for this entry
                $responseEntry = new FHIRBundle\FHIRBundleEntry();
                $bundleResponse = new FHIRBundle\FHIRBundleResponse();

                try {
                    //$repositoryClass = "Mi2\\Emr\\Contracts\\{$resourceKey}RepositoryInterface";
                    //$repository = App::make( $repositoryClass );

                    $adapterClass = "\\Mi2\\FHIR\\Adapters\\FHIR{$resourceKey}Adapter";
                    $adapter = App::make( $adapterClass );
                    //$adapter = new $adapterClass( $repository );

                    // Figure out what to do with the Resource by processing the Request for the Entry
                    $request = $entry->getRequest();
                    $method = $request->getMethod();

                    // Take action and build appropriate response
                    if ( $method->getValue() == 'POST' ) {
                        // Store the Resource and get the newly created interface
                        // TODO check to make sure adapter implements these methods
                        $interface = $adapter->modelToInterface( $resource );
                        $storedInterface = $adapter->storeInterface( $interface );

                        // Build response
                        $bundleResponseStatus = new FHIRString();
                        $bundleResponseStatus->setValue('201 Created');
                        $bundleResponse->setStatus( $bundleResponseStatus );

                        $bundleResponseLocation = new FHIRUri();
                        $bundleResponseLocation->setValue("{$resourceKey}/{$interface->getId()}");
                        $bundleResponse->setLocation( $bundleResponseLocation );

                    }

                    $responseResource = $adapter->interfaceToModel( $storedInterface );
                    $responseResourceId = new FHIRId();
                    $responseResourceId->setValue( $interface->getId() );
                    $responseResource->setId( $responseResourceId );
                    $responseResourceContainer = new FHIRResourceContainer();
                    $responseResourceContainer->{$resourceKey} = $responseResource;

                    $responseEntry->setResource( $responseResourceContainer );

                } catch ( Exception $e ) {
                    // TODO Put error codes in response
                    // Build error response
                    $bundleResponseStatus = new FHIRString();
                    $bundleResponseStatus->setValue('500 Internal Server Error');
                    $bundleResponse->setStatus( $bundleResponseStatus );
                }

                $responseEntry->setResponse( $bundleResponse );
                $fhirResponseBundle->addEntry( $responseEntry );

            }

        } else {
            // Error, the Resource does not match, expecting a Bundle,
            // // but got something else.
        }

        // Complete the response
        $fhirBundleType = new FHIRBundleType();
        $fhirBundleType->setValue( 'transaction-response' );
        $fhirResponseBundle->setType( $fhirBundleType );

        return $fhirResponseBundle;
    }
59640
public function store(Request $request)
    {
//        // handle permission
//        $request = $this->handlePermission(__FUNCTION__, $request);

        // Create Response Model
        $response = new ResponseModel();

        if (!isset($userId)) {
            $userId = 1;
        }

        //add author id into the request if doesn't exist
        if (is_null($request->get('author_id'))) {
            $request['author_id'] = $userId;
        }

        //add user id into the request if doesn't exist
        if (is_null($request->get('user_id'))) {
            $request['user_id'] = $userId;
        }

        $validationErrors = $this->checkRequestValidation($request, $this->storeValidateArray);

        if ($validationErrors != null) {
            if (env('APP_DEBUG', false)) {
                $response->setData(collect($validationErrors->toArray()));
            }
            $response->setMessage($this->getTrans(__FUNCTION__, 'validation_failed'));
            $response->setStatus(false);
            $response->setError(99);
            return SmartResponse::response($response);

        }

        try {
            // get result of model creation
            $result = $this->model->create($request->all());
            // sync many to many relation
            foreach ($this->pivotFields as $pivotField) {
                if (collect($request[$pivotField])->count()) {
                    $pivotField = (new StringHelper())->toCamel($pivotField);
                    $this->model->find($result['id'])->$pivotField()->sync(json_decode($request[$pivotField]));
                }
            }
            $response->setMessage($this->getTrans('store', 'successful'));


            $response->setData($this->model
                ->where($this->model->getKeyName(), $result['id'])
                ->with(collect($this->updateLoad)->count() == 0 ? $this->indexLoad : $this->updateLoad)
                ->get());

            $response->setStatus(true);
        } catch (QueryException $exception) {
            $response->setError($exception->getCode());
            $response->setMessage($this->getTrans('store', 'failed'));
            $response->setStatus(false);
            if (env('APP_DEBUG', false)) {
                $response->setData(collect($exception->getMessage()));
            }
        }
        return SmartResponse::response($response);
    }
214613
public function store(Request $request)
    {
        $this->validate($request, ['text' => 'required|max:64|regex:/^[ a-zA-Z0-9_.-]*$/']);

        // Check if the tag already exists and if so silently return it.
        $tag = Tag::where(DB::raw('LOWER(text)'), strtolower($request->text))->first();
        if(!$tag){
            $tag = new Tag();
            $tag->user_id = $request->user()->id;
            $tag->text = $request->text;
            $tag->save();
        }

        $results = fractal()->item($tag, new TagTransformer());
        return response()->json($results);
    }
533510
public function store(Request $request)
    {
        // Instantiate a new model item.
        $modelClass = $this->getModelClass();
        $item = new $modelClass;

        // Validate the request.
        $this->validate($request, $item->getValidationRules());

        // Create the new item.
        $itemData = $request->all();
        $item->fill($itemData);
        $item->save();

        $newItem = call_user_func([$this->getModelClass(), 'find'], $item->id)->toArray();
        return $this->generateResponse($this->modelTableName, $newItem);
    }
55342
public function store(Request $request)
    {
        $request = $this->processRequest($request);

        if ($request === true) {
            return $this->redirection();
        }

        $this->validate($request, $this->model->rules());

        $this->model = $this->model->create($request->all());

        $saved = $this->afterSaving($request);

        if ($saved) {
            return $this->redirection();
        }
    }
71456
public function store(Request $request)
    {
        $this->validation->make($request->all(), [
            'name' => 'required|max:255',
            'redirect' => ['required', $this->redirectRule],
        ])->validate();

        return $this->clients->create(
            $request->user()->getKey(), $request->name, $request->redirect
        )->makeVisible('secret');
    }
532089
public function store( Request $request )
    {
        $data = $request->getContent();
        $patientInterface = $this->patientAdapter->toPatientInterface( $data );
        $this->patientRepository->create( $patientInterface );
        // TODO return response code
    }
57112
public function store(Request $request)
    {
        $this->authorize('createCategories');

        $this->validate($request, [
            'title'             => ['required'],
            'weight'            => ['required'],
            'enable_threads'    => ['required'],
            'private'           => ['required']
        ]);

        $category = $this->model()->create($request->only(['category_id', 'title', 'description', 'weight', 'enable_threads', 'private']));

        return $this->response($category, 201);
    }
777051
public function store(Request $request)
    {
        $this->validate($request, [
            'author_id' => ['required', 'integer'],
            'title'     => ['required'],
            'content'   => ['required']
        ]);

        $category = Category::find($request->input('category_id'));

        $this->authorize('createThreads', $category);

        if (!$category->threadsEnabled) {
            return $this->buildFailedValidationResponse($request, trans('forum::validation.category_threads_enabled'));
        }

        $thread = $this->model()->create($request->only(['category_id', 'author_id', 'title']));
        Post::create(['thread_id' => $thread->id] + $request->only('author_id', 'content'));

        return $this->response($thread, 201);
    }
399130
public function store(Request $request)
    {
        $data = $this->validate(request(), [
            'old_url' => 'required',
            'new_url' => 'required'
        ]);

        Redirection::create($data);

        session()->flash('success', 'Redirección registrada con éxito!');
        return redirect()->route('redirecciones.index');
    }