Add a postal address.

@param \Illuminate\Http\Request $request
@return \Illuminate\Http\RedirectResponse
510026
public function postPostalAddress(Request $request)
    {
        $this->validates(
            $request->all(),
            [
                'name' => 'required',
                'street1' => 'required',
                'city' => 'required',
                'county' => 'required',
                'postcode' => 'required',
                'country' => 'required',
            ]
        );

        $pa = new PostalAddress;

        $pa->name = $request->input('name');
        $pa->street1 = $request->input('street1');
        $pa->street2 = $request->input('street2');
        $pa->city = $request->input('city');
        $pa->county = $request->input('county');
        $pa->postcode = $request->input('postcode');
        $pa->country = $this->country($request->input('country'))['alpha2'];
        $pa->added = time();

        $pa->user()->associate(Auth::user());

        $pa->save();

        return redirect('/account/postal-addresses')->withStatus('Postal address added.');
    }
39749
public function postCollectionAddress(Request $request)
    {
        $purchase = Purchase::findOrFail($request->input('purchase_id'));

        if ($purchase->item->seller->userId != Auth::user()->userId) {
            return redirect('/inventory/sold')->withErrors([
                "You are not the seller of this item."
            ]);
        }

        if ($purchase->deliveryOption) {
            return redirect('/inventory/sold')->withErrors([
                "This item is not due to be collected."
            ]);
        }

        if ($purchase->hasAddress()) {
            return redirect('/inventory/sold')->withErrors([
                "You have already provided a collection address for this item."
            ]);
        }

        if ($request->input('postal_address') == 'add') {
            $postal_address = new PostalAddress;

            $postal_address->name = $request->input('name');
            $postal_address->street1 = $request->input('street1');
            $postal_address->street2 = $request->input('street2');
            $postal_address->city = $request->input('city');
            $postal_address->county = $request->input('county');
            $postal_address->country = $request->input('country');
            $postal_address->postcode = $request->input('postcode');

            $postal_address->user()->associate(Auth::user());

            if (!Iso3166::exists($request->input('country'))) {
                return redirect()->back()->withErrors([
                    'country' => 'Please select a valid country.'
                ]);
            }

            if ($request->input('remember')) {
                $postal_address->save();
            }
        } elseif (!$postal_address = PostalAddress::find($request->input('postal_address'))) {
            return redirect()->back()->withErrors(['postal_address' => 'Please select a valid postal address.']);
        } elseif ($postal_address->user != Auth::user()) {
            return redirect()->back()->withErrors(['postal_address' => 'You can only select your own postal addresses.']);
        }

        $purchase->useAddress($postal_address);

        $purchase->save();

        $purchase->buyer->sendEmail(
            'Your item is ready for collection',
            'emails.item.collection',
            [
                'item_name' => $purchase->item->name,
                'seller_name' => $purchase->name,
                'seller_street1' => $purchase->street1,
                'seller_street2' => $purchase->street2,
                'seller_city' => $purchase->city,
                'seller_county' => $purchase->county,
                'seller_postcode' => $purchase->postcode,
                'seller_country' => Iso3166::get($purchase->country)->name,
            ]
        );

        return redirect('/inventory/sold')->withStatus("Your collection address has been saved and sent to the buyer.");
    }
234684
public function addAction(Request $request)
    {
        $resource = $this->mapper->create($this->validateRequestParameters($request));

        return new Response('', 201, array('Location' => $this->mapper->generateReadUrl($resource)));
    }
227832
public function handleAction(Request $request): Envelope
    {
        $request->attributes->set('pbjx_redact_error_message', false);
        $envelope = EnvelopeV1::create();
        if (!$this->isRequestMethodOk($envelope, $request) || !$this->isContentTypeOk($envelope, $request)) {
            return $envelope;
        }

        if ($request->isMethod('GET')) {
            $json = PbjxToken::urlsafeB64Decode($request->query->get('pbj'));
        } elseif (0 === strpos($request->headers->get('Content-Type'), 'multipart/form-data')) {
            $json = $request->request->get('pbj');
        } else {
            $json = $request->getContent();
        }

        $json = (string)$json;
        $data = json_decode($json, true) ?: [];
        if (!$this->isJsonOk($envelope, $request)) {
            return $envelope;
        }

        $pbjxCategory = $request->attributes->get('pbjx_category');
        if (false !== strpos($pbjxCategory, '_')) {
            $pbjxCategory = str_replace('_', '', $pbjxCategory);
            $request->attributes->set('pbjx_category', $pbjxCategory);
        }

        try {
            $expectedCurie = SchemaCurie::fromString(sprintf(
                '%s:%s:%s:%s',
                $request->attributes->get('pbjx_vendor'),
                $request->attributes->get('pbjx_package'),
                $pbjxCategory,
                $request->attributes->get('pbjx_message')
            ));

            $request->attributes->set('pbjx_curie', $expectedCurie->toString());
            $schemaId = isset($data[Schema::PBJ_FIELD_NAME]) ? SchemaId::fromString($data[Schema::PBJ_FIELD_NAME]) : null;

            /** @var Message $class */
            if (null === $schemaId) {
                $class = MessageResolver::resolveCurie($expectedCurie);
                $schema = $class::schema();
                $schemaId = $schema->getId();
            } else {
                $class = MessageResolver::resolveId($schemaId);
            }

            if ($schemaId->getCurie() !== $expectedCurie) {
                throw new \InvalidArgumentException(
                    sprintf(
                        'The resolved schema [%s] doesn\'t match expected curie [%s].',
                        $schemaId->toString(),
                        $expectedCurie->toString()
                    )
                );
            }
        } catch (\Throwable $e) {
            return $envelope
                ->set('code', Code::INVALID_ARGUMENT)
                ->set('http_code', HttpCode::HTTP_UNPROCESSABLE_ENTITY())
                ->set('error_name', 'UnprocessableEntity')
                ->set('error_message', $e->getMessage());
        }

        $request->attributes->set('pbjx_input', $data);
        $request->attributes->set('pbjx_bind_unrestricted', $request->attributes->getBoolean('pbjx_bind_unrestricted'));

        try {
            /** @var Command|Event|PbjxRequest $message */
            $message = $class::fromArray($data);
            $message->set('ctx_correlator_ref', $envelope->generateMessageRef());
        } catch (\Throwable $e) {
            return $envelope
                ->set('code', Code::INVALID_ARGUMENT)
                ->set('http_code', HttpCode::HTTP_UNPROCESSABLE_ENTITY())
                ->set('error_name', 'UnprocessableEntity')
                ->set('error_message', $e->getMessage());
        }

        $request->attributes->set(
            'pbjx_redact_error_message',
            !$request->attributes->getBoolean('pbjx_console')
        );

        if (!$this->isPbjxTokenOk($envelope, $request, $json)) {
            return $envelope;
        }

        // allows for functional tests/postman tests/etc. to post pbjx but
        // not actually run them.  this is most important for commands/events
        // which can change state but for request, you'd typically not use
        // dry run because you need to get a response in order to make assertions.
        if ($request->headers->has('x-pbjx-dry-run')) {
            return $envelope
                ->set('code', Code::OK)
                ->set('http_code', HttpCode::HTTP_ACCEPTED())
                ->set('message_ref', $message->generateMessageRef());
        }

        if ($message instanceof Command) {
            return $this->handleCommand($envelope, $request, $message);
        }

        if ($message instanceof Event) {
            return $this->handleEvent($envelope, $request, $message);
        }

        if ($message instanceof PbjxRequest) {
            return $this->handleRequest($envelope, $request, $message);
        }

        $request->attributes->set('pbjx_redact_error_message', false);
        return $envelope
            ->set('code', Code::INVALID_ARGUMENT)
            ->set('http_code', HttpCode::HTTP_UNPROCESSABLE_ENTITY())
            ->set('error_name', 'UnprocessableEntity')
            ->set(
                'error_message',
                sprintf('This service does not allow you to submit [%s] messages.', $schemaId->toString())
            );
    }
45797
public function postEdit(Request $request)
    {

        $form = FormBuilder::create(get_class($this->form), [
            'model' => $this->model
        ]);


        if ($form->hasError()) {
            return $form->validateAndRedirectBack();
        }

        $result = $this->beforeSave();

        if ($result != null) {
            return $result;
        }

        $result = $this->save($this->dataToSave($request), $request);


        if ($this->isTranslatableModel() && !$this->model->hasTranslation($this->model->getTable(), $this->model->getKey())) {
            $this->saveTranslation(app()->getLocale());
        }

        if ($result != null) {
            return $result;
        }

        return redirect()->to(action($this->getControllerNameForAction().'@getIndex'));

    }
707811
public function store(Request $request)
    {
        $slug = $this->getSlug($request);

        $dataType = Admin::model('DataType')->where('slug', '=', $slug)->first();
        $model = app($dataType->model_name);

        // Check permission
        $this->authorize('edit', $model);

        if ($model instanceof ModelValidator) {
            // Model validation
            $validator = $model->validate($request);
        } else {
            // Crud validation
            $validator = $this->validateCrud($request->all(), $dataType->addRows);
        }

        if ($validator->fails()) {
            return response()->json(['errors' => $validator->messages()]);
        }

        if (!$request->ajax()) {
            $data = $this->insertUpdateData($request, $slug, $dataType->addRows, new $dataType->model_name());

            event(new CrudDataAdded($request, $slug, $dataType, $data));

            $redirect = redirect(admin_route($dataType->slug . ".index"));

            if ($dataType->isBackToParentCrud()) {
                $requestQuery = (object) $request->query();

                $redirect = redirect(admin_route($requestQuery->crud_slug . '.' . $requestQuery->crud_action, $requestQuery->crud_id));
            }

            if ($dataType->isBackToEdit()) {
                $redirect = redirect(admin_route($dataType->slug . '.edit', $data->id));
            }

            return $redirect->with([
                'message'    => __('admin.generic.successfully_updated')." {$dataType->display_name_singular}",
                'alert-type' => 'success',
            ]);
        }
    }
1099923
public function store(Request $request)
    {
        $name = \Transliteration::clean_filename(strtolower($request->label));
        $label = $request->label;

        try
        {
            WorkflowState::create([
                            'name' => $name,
                            'label' => $label,
                ]);
        }
        catch(\Illuminate\Database\QueryException $e){
            // do what you want here with $e->getMessage();
            return redirect()->route('state')->with('message', 'Error');
        }

        return redirect()->route('state')->with('message', 'Add data success');
    }
1095475
public function informationsAction(Request $request)
    {
        if (null !== $redirect = $this->validateStep('information')) {
            return $redirect;
        }

        $cart = $this->getCart();

        /** @var \Ekyna\Bundle\UserBundle\Model\UserInterface $user */
        $user = $this->getUser();
        if (null !== $user) {
            $cart
                ->setUser($user)
                ->setGender($user->getGender())
                ->setFirstName($user->getFirstName())
                ->setLastName($user->getLastName())
                ->setEmail($user->getEmail())
            ;
        }

        $form = $this->createForm('ekyna_cart_step_information', $cart);

        $form->handleRequest($request);
        if ($form->isValid()) {
            $event = new OrderEvent($cart);
            $this->getDispatcher()->dispatch(OrderEvents::CONTENT_CHANGE, $event);
            if (!$event->isPropagationStopped()) {
                if ($cart->requiresShipment()) {
                    return $this->redirect($this->generateUrl('ekyna_cart_shipment'));
                }
                return $this->redirect($this->generateUrl('ekyna_cart_payment'));
            } else {
                $event->toFlashes($this->getFlashBag());
            }
            return $this->redirect($this->generateUrl('ekyna_cart_informations'));
        }

        return $this->render('EkynaCartBundle:Cart:informations.html.twig', [
            'form' => $form->createView(),
            'cart' => $cart,
         	'user' => $user,
        ]);
    }
916355
public function addAction(Request $request)
    {
        $cm = new CronManager();
        $cron = new Cron();
        $this->addFlashFromCronManager($cm);
        $form = $this->createCronForm($cron);

        $form->handleRequest($request);
        if ($form->isSubmitted() && $form->isValid()) {
            $cm->add($cron);
            $this->addFlashFromCronManager($cm);

            return $this->redirect($this->generateUrl('BCCCronManagerBundle_index'));
        }

        return $this->render('@BCCCronManager:Default:index.html.twig', array(
            'crons' => $cm->get(),
            'raw'   => $cm->getRaw(),
            'form'  => $form->createView(),
        ));
    }
1293325
public function postAction(Request $request)
    {
        try {
            $this->checkArguments($request);
            $contact = $this->getContactManager()->save(
                $request->request->all()
            );
            $apiContact = $this->getContactManager()->getContact(
                $contact,
                $this->getLocale($request)
            );
            $view = $this->view($apiContact, 200);
            $context = new Context();
            $context->setGroups(static::$contactSerializationGroups);
            $view->setContext($context);
        } catch (EntityNotFoundException $enfe) {
            $view = $this->view($enfe->toArray(), 404);
        } catch (MissingArgumentException $maex) {
            $view = $this->view($maex->toArray(), 400);
        } catch (RestException $re) {
            $view = $this->view($re->toArray(), 400);
        }

        return $this->handleView($view);
    }
837157
public function createAction(Request $request)
    {
        $this->registerBreadcrubms()->addItem($this->get("translator")->trans("Add"));

        $entity = $this->getNewEntity();
        $form = $this->createCreateForm($entity);

        $form->handleRequest($request);

        if ($form->isValid()) {
            $em = $this->getDoctrine()->getManager();

            try {
                if ($form->get("saveAndPublish")->isClicked()) {
                    $entity->setPublished(1);
                }
            } catch (OutOfBoundsException $e) {

            }

            $em->persist($entity);

            $em->flush();

            $this->get('session')->getFlashBag()->add('notice', $this->getEntityName() . ' has been created!');

            if ($form->get("saveAndExit")->isClicked()) {
                return $this->redirect($this->generateUrl($this->getRouteName(), $this->getRouteParams()));
            } else {
                try {
                    if ($form->get("addNext")->isClicked()) {
                        return $this->redirect($this->generateUrl($this->getRouteName() . "Add", $this->getRouteParams()));
                    }
                } catch (OutOfBoundsException $e) {

                }
                return $this->redirect($this->generateUrl($this->getRouteName() . "Edit", $this->getRouteParams(['id' => $entity->getId()])));
            }
        }

        return $this->render($this->getListTemplate() . ":edit.html.twig", [
            'entity' => $entity,
            'form' => $form->createView()
        ]);
    }
1275036
public function addAction(Request $request)
    {
        $feature = new Feature();

        $form = $this->get('form.factory')->create(FeatureType::class, $feature);

        if($form->handleRequest($request)->isValid()){

            $em = $this->getDoctrine()->getManager();
            $em->persist($feature);
            $em->flush();

            $request->getSession()->getFlashBag()->add('success', 'Caractéristique bien ajoutée');
            return $this->redirect($this->generateUrl('product_feature_table'));
        }
        return $this->render('DyweeProductBundle:Feature:add.html.twig', array('form' => $form->createView()));
    }
360736
public function update(Request $request)
    {
        $this->validate($request, [
            'navbar_color' => 'max:255',
            'favicon'      => 'url|max:2000',
        ]);
        Customization::first()->update([
            // 'color'             => $request->input('color'),
            // 'background_color'  => $request->input('background_color'),
            'navbar_color'      => $request->navbar_color,
            'favicon'           => $request->favicon,
        ]);

        return redirect()->route('laralum::settings.index', ['p' => 'Customization'])->with('success', __('laralum_customization::general.updated_settings'));
    }
850107
public function store(Request $request)
    {
        /** @noinspection PhpUndefinedMethodInspection */
        $request->validate([
            'email' => 'required|email',
            'name' => 'max:36',
        ]);
        $invitedMember = $this->createInvitedMember($request);
        $memberInvitation = $this->createMemberInvitation($request->email, $invitedMember->id);
        $invitedMember->notify(new MemberInvited($memberInvitation));
        /** @noinspection PhpUndefinedMethodInspection */
        return fractal($memberInvitation, new MemberInvitationTransformer())
            ->includeInvitedMember()
            ->withResourceName('memberInvitation')
            ->respond();
    }
136831
public function emailsDashboardAction(Request $request)
    {
        $form = $this->createForm(SentEmailType::class);
        $form->handleRequest($request);
        $searchParams = $form->getData();
        /** @var SentEmailRepository $repository */
        $repository = $this->getDoctrine()->getManager()->getRepository(SentEmail::class);
        $query = $repository->search($searchParams);
        $pagination = $this->get('knp_paginator')->paginate($query, $request->query->getInt('page', 1));

        return $this->render('AzineEmailBundle::emailsDashboard.html.twig',
            array('form' => $form->createView(), 'pagination' => $pagination));
    }
370560
public function sendMailout(Request $request)
    {
        $this->validate(
            $request,
            [
                'users'   => 'required|array',
                'subject' => 'required|min:4',
                'body'    => 'required|min:10',
            ]
        );

        $count = 0;

        foreach (User::all() as $user) {
            if (in_array($user->userId, $request->input('users'))) {
                $user->sendEmail(
                    $request->input('subject'),
                    'mustard::emails.mailout',
                    [
                        'body'     => $request->input('body'),
                        'username' => $user->username,
                    ]
                );

                $count++;
            }
        }

        return redirect()->back()->withStatus(trans('mustard::admin.mailout_sent', ['count' => $count]));
    }
1175076
public function postAction(Request $request)
    {
        $file = new File();
        $request = $this->requestManager->updateFileRequest($request);

        if ($formData = $request->get('metadata')) {
            $file = $this->restUtils->validateRequest($formData, $this->getModel());
        }

        /** @var FileModel $model */
        $model = $this->getModel();
        $file = $this->fileManager->handleSaveRequest($file, $request, $model);

        // Set status code and content
        $response = $this->getResponse();
        $response->setStatusCode(Response::HTTP_CREATED);
        $response->headers->set(
            'Location',
            $this->getRouter()->generate('gravitondyn.file.rest.file.get', array('id' => $file->getId()))
        );
        return $response;
    }