Process the form for store/update of the given resource.

@param \Illuminate\Http\Request $request

@return \Illuminate\Http\JsonResponse
325102
public function execute(Terminal $terminal, Request $request)
    {
        $error = $terminal->call($request->get('command'));

        return response()->json([
            'jsonrpc' => $request->get('jsonrpc'),
            'id' => $request->get('id'),
            'result' => $terminal->output(),
            'error' => $error,
        ]);
    }
1350313
public function update(Request $request)
    {
        // Carregar ID
        $id = $this->getId($request);

        // Carregar objeto JSON
        $obj = $this->getJsonContent($request);
        if (is_null($obj)) {
            $this->error('JSON invalid', 500);
        }

        // Salvar
        $this->setValues($obj, $id);

        return response()->json((object)['success' => true]);
    }
735778
public function handle(Request $request)
    {
        //get the correct method
        if ($this->method === 'GET') {
            $values = $request->query->all();
        } else {
            $values = $request->request->all();
        }

        // The form is submitted if at least one field is present
        if (count(array_intersect_key($values, $this->rows)) > 0) {
            return $this->submitForm($values);
        }
    }
629857
public function store(Request $request)
    {
        $this->authorize('create', File::class);
        $input = $this->validator->validate('create');
        if ($request->hasFile('file')) {
            $uploadedFile = $request->file('file');
            if ($uploadedFile->isValid()) {
                try {
                    $file = $this->fileRepo->create($input, $uploadedFile, auth()->user());
                    return $this->respondWithSuccess($file, new FileTransformer);
                } catch (RepositoryValidationException $e) {
                    return $this->respondWithError($e->getMessage());
                }
            }
        }
        return $this->respondWithError('The file could not be uploaded - invalid or missing file');
    }
570409
public function jsonSaveAction(Request $request)
    {
        //@FIXME: This code need to be moved to ContentController somehow.
        $this->save($request);

        $response = new Response(json_encode(['status' => 'ok']));
        $response->headers->set("Content-Type", 'application/json');

        return $response;
    }
263027
public function updateValueAction(Request $request)
    {
        $name = $request->get('name');
        $value = $request->get('value');

        $manager = $this->get('ongr_settings.settings_manager');
        $manager->update($name, ['value' => $value]);

        return new JsonResponse(['error' => false]);
    }
143424
public function save(Request $request)
    {
        if (method_exists($this, 'beforeSave')) {

            $response = $this->beforeSave($request);

            if ($response instanceof Response) {
                return $response;
            }
        }

        $app = $this->app;
        $store = $this->getStore();

        $app['db']->beginTransaction();

        try {
            $record = $store->save($request->request->all());

            if (!is_array($record)) {
                $response = [
                    'success' => true,
                    'record' => $record
                ];
            } else {
                $response = [
                    'success' => false,
                    'code' => $record['code'],
                    'message' => $record['message']
                ];
            }

            $app['db']->commit();
            
        } catch(\Exception $e) {
            $app['db']->rollback();

            $response = [
                'success' => false,
                'code' => $e->getCode(),
                'message' => $e->getMessage()
            ];

        }

        if (method_exists($this, 'afterSave')) {
            $response = $this->afterSave($request, $response);

            if ($response instanceof Response) {
                return $response;
            }
        }

        return $app->json($response);
    }
975646
public function store(Request $request)
    {
        // Validate the form data
        $result = $this->validate($request, [
            'name' => 'required',
            'slug' => 'required|alpha_dash|unique:roles',
        ]);

        // Create the Role
        $role = Sentinel::getRoleRepository()->createModel()->create([
            'name' => trim($request->get('name')),
            'slug' => trim($request->get('slug')),
        ]);

        // Cast permissions values to boolean
        $permissions = [];
        foreach ($request->get('permissions', []) as $permission => $value) {
            $permissions[$permission] = (bool)$value;
        }

        // Set the role permissions
        $role->permissions = $permissions;
        $role->save();

        // All done
        if ($request->expectsJson()) {
            return response()->json(['role' => $role], 200);
        }

        session()->flash('success', "Role '{$role->name}' has been created.");
        return redirect()->route('roles.index');
    }
205499
public function store(Request $request)
    {
        // check if user has permissions to access this link
        if(!User::hasAccess('Language', (isset($request->id)) ? 'update' : 'create')) {
            return $this->noPermission();
        }
        // custom messages for validation
        $messages = array(
            'name.required'=>'Language name is required',
        );

        $validatorValues = [
            'name' => 'required',
            'isDefault' => 'required',
            'isVisible' => 'required',
            'slug' => 'required|max:500|unique:languages',
        ];
        if(isset($request->id)) {
            unset($validatorValues['slug']);
        }

        // validation
        $validator = Validator::make($request->all(), $validatorValues, $messages);
        // if validation fails return json response
        if ($validator->fails()) {
            return $this->response("Please check all required fields!", 400, null, false, false, true, $validator->errors());
        }

        if($request->isDefault == true) {
            // remove the current default language ( set it to non-default ) if this new one is the default
            Language::where('isDefault', 1)->update(
                [
                'isDefault'    => 0,
                ]
            );
        }

        // createdByUserID, slug and nativeName don't need to be updated
        if(isset($request->id)) {
            $language = Language::findOrFail($request->id);
        }else{
            $language = new Language();
            $language->createdByUserID = Auth::user()->userID;
            $language->slug = $request->slug;
            $language->nativeName = $request->nativeName;
        }
        $language->name = $request->name;
        $language->isDefault = $request->isDefault;
        $language->isVisible = $request->isVisible;

        if($language->save()) {
            // create virutal column for slug of every post type in the created language
            $allPostTypes = PostType::all();
            foreach ($allPostTypes as $postType){
                PostType::createVirtualColumnsForSlug($postType->slug, $language->slug);
            }

            // create labels
            if(!isset($request->id)) {
                $this->createNewLanguageLabels($language->slug);
            }

            $redirectParams = parent::redirectParams($request->redirect, 'language', $language->languageID);
            $result = $this->response('Language is stored', 200, $language->languageID, $redirectParams['view'], $redirectParams['redirectUrl']);
        }else{
            $result = $this->response('Language could not be stored. Internal server error. Please try again later', 500);
        }
        return $result;

    }
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);
    }
1200178
public function updateManyToManyAction(Request $request)
    {
        /** @var AbstractAdmin $admin */
        $admin = $this->getAdmin();

        $admin->checkAccess('edit');

        $em = $admin->getDoctrine()->getManager();

        $ids = $request->request->get('value');
        $id = $request->request->get('pk');

        $field = $request->request->get('field');

        $object = $admin->getObject($id);

        /** @var \Sonata\DoctrineORMAdminBundle\Model\ModelManager $mm */
        $mm = $admin->getModelManager();

        $ClassMetadata = $mm->getMetadata($admin->getClass());

        $associationMapping = $ClassMetadata->getAssociationMapping($field);

        $items = $em->getRepository($associationMapping['targetEntity'])->findBy([
            'id' => $ids,
        ]);

        \call_user_func([$object, 'set' . ucfirst($field)], $items);

        $admin->update($object);

        $result = [
        ];

        $associationAdmin = $admin->getAdminByClass($associationMapping['targetEntity']);

        foreach ($items as $item) {
            if (method_exists($item, 'getId') && method_exists($item, 'getName')) {
                $result[] = [
                    'id' => $item->getId(),
                    'label' => $item->getName(),
                    'edit_url' => $associationAdmin->generateObjectUrl('edit', $item),
                ];
            }
        }

        return new JsonResponse([
            'items' => $result,
        ]);
    }
1242464
public function indexAction(Request $request)
    {
        $layouts = $this->get('opifer.content.layout_manager')->getRepository()
            ->findAll();

        $data = $this->get('jms_serializer')->serialize($layouts, 'json');

        return new Response($data, 200, ['Content-Type' => 'application/json']);
    }
1283509
public function store(Request $request)
    {
        $this->manager->resetPath($request->folder);

        if (empty($request->name)) {
            return $this->json('Name property is required.', 422);
        }

        if (!$this->manager->blobExists()) {
            return $this->json('Folder not found.', 404);
        }

        $result = $this->manager->makeDirectory($request->name)->fullDetails();

        return $this->json($result);
    }
976047
public function handle(Request $request)
	{
		// execute response
		$response = $this->next($request);

		// only do on json data
		if (!$response->isJson())
		{
			return $response;
		}

		// get the response content and json decode
		$content = json_decode($response->getContent());

		// get date keys from response options
		$this->dateKeys = array_merge(
			$this->dateKeys,
			$response->getTransformKeys('dates')
		);

		// make sure to handle array different then a single object
		if (is_array($content))
		{
			// loop through each item in array and covert dates
			foreach ($content as $key => $value)
			{
				$content[$key] = $this->convertDateKeysInObjects($value);
			}
		}
		else
		{
			// convert single object dates
			$content = $this->convertDateKeysInObjects($content);
		}

		// set the response content to modified content
		$response->setContent(json_encode($content));

		// return response
		return $response;
	}
1047349
public function upload(Request $request)
    {
        $json = [];
        foreach ($request->file('file') as $file) {
            $this->storage->putFile($request->get('directory'), $file);
        }

        $json['success'] = trans('admin::image.success.upload');

        return response()
            ->json($json);
    }
330729
public function update(Request $request) {

	    // Grab these inputs to determine if we need to return to the edit form after updating
        $return_to_edit = $request->input('return_to_edit');
        $record_id      = $request->input('id');

        // Launch the command, and capture the results (I should refactor "$response", but have not yet!)
        $response = $this->dispatchFrom(UpdateBaseCommand::class, $request);

        Session::flash('status_code', $response['status_code'] );


        ///////////////////////////////////////////////////////////////
        //              Problems with the update                     //
        ///////////////////////////////////////////////////////////////
        //        Session::flash('message', $message);

        if ($response['status_text'] == "validation_failed")
        {
            // flash message
            if (is_object($response['errorMessages'])) {
                Session::flash('message', $response['errorMessages']->first());
            } else {
                Session::flash('message', $response['errorMessages']);
            }

            // Return to the edit form with error messages
            return Redirect::back()
                ->withInput($response['data'])
                ->withErrors($response['errorMessages']);
        }


        if ($response['status_text'] == "persist_failed")
        {
            $message = "Persist failed. It does not happen often, but Laravel's save failed. The database operation is called at Lasallecms\Lasallecmsapi\\".$this->model->table."\\".$this->model->classname_formprocessor_delete.". MySQL probably hiccupped, so probably just try again.";

            Session::flash('message', $message);

            // Return to the edit form with error messages
            return Redirect::back()
                ->withInput($response['data']);
        }



        ///////////////////////////////////////////////////////////////
        //                  Update Succeeded!                        //
        ///////////////////////////////////////////////////////////////

        if ( empty($response['data']['title']) ) {
             $response['data']['title'] = strtoupper($response['data']['composite_title']);
        }

        ///////////////////////////////////////////////////////////////
        //                     Event?                                //
        ///////////////////////////////////////////////////////////////

        // if there is an event to fire where need to show an "are you sure" confirmation first
        if ($response['status_text'] == "update_successful_now_confirm_before_firing_event") {

            $message =  "You successfully updated the ".strtolower($this->model->model_class)." ".strtoupper($response['data']['title'])."!";

            Session::flash('message', $message);

            return view('lasallecrmlistmanagement::confirmations.confirm_send_to_list', [
                'user'                 => Auth::user(),
                'data'                 => $response['data'],
                'message'              => $message,
                'HTMLHelper'           => HTMLHelper::class,
            ]);
        }

        // if there is an event to fire with *no* "are you sure" confirmation first
        if ($response['status_text'] == "update_successful_with_event_fired") {

            $message =  "You successfully updated the ".strtolower($this->model->model_class)." ".strtoupper($response['data']['title'])." *and* ".$response['data']['eventDescription']."!";

            Session::flash('message', $message);
        }

        ///////////////////////////////////////////////////////////////
        //                     Redirect                              //
        ///////////////////////////////////////////////////////////////

        // Redirect to the edit form?
        if ($return_to_edit == "Save & Edit") {
            return Redirect::route('admin.'.$this->model->resource_route_name.'.edit', $record_id);
        }

        return Redirect::route('admin.'.$this->model->resource_route_name.'.index');
    }
1163348
public function store(Request $request)
    {
        $this->validate($request, [
            'title' => 'required|max:255',
            'type'  => 'required|max:255|alpha|unique:navigation,type',
        ]);

        $navigation = new Navigation;
        $navigation->fill($request->all());
        $navigation->published = $request->get('published', false);
        $navigation->save();
        flash()->success(trans('cms::navigation.store.success'));

        return redirect()->route('administrator.navigation.index');
    }