Inheritance: extends Illuminate\Foundation\Http\FormRequest
Esempio n. 1
0
 /**
  * Just passes everything into the update. If there's a stricter
  * requirement,
  *
  * @param Request $request
  * @param $id
  * @return mixed
  */
 public function update(Request $request, $id)
 {
     if ($this->repository->find($id)) {
         return $this->repository->update($id, $request->all());
     }
     return null;
 }
 /**
  * updates activity sector
  * @param                      $id
  * @param Request              $request
  * @param SectorRequestManager $sectorRequestManager
  * @return \Illuminate\Http\RedirectResponse
  */
 public function update($id, Request $request, SectorRequestManager $sectorRequestManager)
 {
     $activityData = $this->activityManager->getActivityData($id);
     if (Gate::denies('ownership', $activityData)) {
         return redirect()->back()->withResponse($this->getNoPrivilegesMessage());
     }
     $this->authorizeByRequestType($activityData, 'sector');
     $sectors = $request->all();
     foreach ($sectors['sector'] as &$sector) {
         if ($sector['sector_vocabulary'] == 1 || $sector['sector_vocabulary'] == '') {
             $sector['sector_vocabulary'] = 1;
             $sector['sector_category_code'] = '';
             $sector['sector_text'] = '';
         } elseif ($sector['sector_vocabulary'] == 2) {
             $sector['sector_code'] = '';
             $sector['sector_text'] = '';
         } else {
             $sector['sector_code'] = '';
             $sector['sector_category_code'] = '';
         }
     }
     if ($this->sectorManager->update($sectors, $activityData)) {
         $this->activityManager->resetActivityWorkflow($id);
         $response = ['type' => 'success', 'code' => ['updated', ['name' => 'Sector']]];
         return redirect()->to(sprintf('/activity/%s', $id))->withResponse($response);
     }
     $response = ['type' => 'danger', 'code' => ['update_failed', ['name' => 'Sector']]];
     return redirect()->back()->withInput()->withResponse($response);
 }
Esempio n. 3
0
 /**
  * Update post
  * @param  Request $request 
  * @param  int  $id      
  * @return void
  */
 public function updatePost(Request $request, $id)
 {
     DB::beginTransaction();
     try {
         $post = Post::findOrFail($id);
         $oldImage = "";
         $inputs = $request->all();
         if ($request->hasFile('images')) {
             $oldImage = public_path() . config('model.posts.path_folder_photo_post') . $post->images;
             $imageFile = $request->file('images');
             $inputs['images'] = $this->__storeImagePost($imageFile);
         } else {
             unset($inputs['images']);
         }
         if ($inputs['type'] == 2) {
             $this->__changeStickyPost($id);
         }
         $post->fill($inputs);
         $post->save();
         if (strlen($oldImage) != 0) {
             if (File::exists($oldImage)) {
                 File::delete($oldImage);
             }
         }
     } catch (Exception $e) {
         DB::rollback();
         throw new Exception("Error Processing Request", 1);
     }
     DB::commit();
 }
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store(Validator $validator, Request $request)
 {
     $messages = $validator->errors();
     $request->session()->flash('status', 'Task was successful!');
     foreach ($messages->all() as $message) {
         print_r($message);
     }
     exit;
 }
Esempio n. 5
0
 public function mailOrder(Request $request)
 {
     $view = 'emails.order';
     $subject = 'New Order Receipt';
     $data = $request->only('product_name', 'message_text', 'email', 'phone');
     $data['title'] = "New Order Email";
     $user = (object) ['email' => '*****@*****.**'];
     return $this->sendTo($user, $subject, $view, $data);
 }
 public function storeOrUpdate(Request $request, $id = null)
 {
     $user = $id ? $this->getById($id) : new User();
     $user->name = $request->input('name');
     $user->email = $request->input('email');
     $user->password = Hash::make($request->input('password'));
     $user->status = UserStatus::ACTIVATED();
     $user->save();
     return $user;
 }
 /**
  * If a post exists, update its properties. If not then create new
  * 
  * @param  Request $request 
  * @param  string  $id
  * @return \Illuminate\Database\Eloquent\Model
  */
 public function storeOrUpdate(Request $request, $id = null)
 {
     $post = $id ? $this->getById($id) : new Post();
     $post->user_id = Auth::id();
     $post->title = $request->input('title');
     $post->body = $request->input('body');
     $post->excerpt = $request->input('excerpt');
     $post->uri = str_slug($request->input('title'));
     $post->status = PostStatus::PUBLISHED();
     $post->save();
     return $post;
 }
 /**
  * Update the specified resource in storage.
  *
  * @param  int                                $organizationId
  * @param CreateOrgReportingOrgRequestManager $createOrgReportingOrgRequestManager
  * @param Request                             $request
  * @return Response
  */
 public function update($organizationId, CreateOrgReportingOrgRequestManager $createOrgReportingOrgRequestManager, Request $request)
 {
     $organization = $this->organizationManager->getOrganization($organizationId);
     if (Gate::denies('belongsToOrganization', $organization)) {
         return redirect()->route('activity.index')->withResponse($this->getNoPrivilegesMessage());
     }
     $this->authorize('edit_activity', $organization);
     $input = $request->all();
     $this->orgReportingOrgManager->update($input, $organization);
     $this->organizationManager->resetStatus($organizationId);
     $response = ['type' => 'success', 'code' => ['updated', ['name' => 'Reporting Organization']]];
     return redirect()->route("organization.show", $organizationId)->withResponse($response);
 }
Esempio n. 9
0
 public function loadRequest(Request $request)
 {
     $class = get_called_class();
     $class = explode('\\', $class);
     $class = end($class);
     $prefix = $class . '_';
     $arr_res = $request->all();
     foreach ($arr_res as $key => $value) {
         if (preg_match("/{$prefix}(?<name>.*)/", $key, $match)) {
             $name = $match['name'];
             $this->{$name} = $value;
         }
     }
 }
Esempio n. 10
0
 /**
  * Get the validation rules that apply to the request.
  *
  * @return array
  */
 public function rules()
 {
     if (Request::has('data')) {
         return ['data' => 'required'];
     }
     return ['judul_berita' => 'required', 'kategori_berita' => 'required', 'isi' => 'required', 'foto' => 'required'];
 }
 /**
  * updates activity title
  * @param                     $id
  * @param Request             $request
  * @param TitleRequestManager $titleRequestManager
  * @return \Illuminate\Http\RedirectResponse
  */
 public function update($id, Request $request, TitleRequestManager $titleRequestManager)
 {
     if (!$this->currentUserIsAuthorizedForActivity($id)) {
         return redirect()->back()->withResponse($this->getNoPrivilegesMessage());
     }
     $activityData = $this->titleManager->getActivityData($id);
     $this->authorizeByRequestType($activityData, 'title');
     $activityTitle = $request->all();
     if ($this->titleManager->update($activityTitle, $activityData)) {
         $this->activityManager->resetActivityWorkflow($id);
         $response = ['type' => 'success', 'code' => ['updated', ['name' => 'Activity Title']]];
         return redirect()->to(sprintf('/activity/%s', $id))->withResponse($response);
     }
     $response = ['type' => 'danger', 'code' => ['update_failed', ['name' => 'Activity Title']]];
     return redirect()->back()->withInput()->withResponse($response);
 }
 /**
  * Overrides getValidatorInstance so we can apply sometimes function
  * @return 
  */
 protected function getValidatorInstance()
 {
     //todo: change validator to handle categories correctly
     return parent::getValidatorInstance();
     //$validator->sometimes('dob', 'valid_date', function($input));
     //return $validator;
 }
Esempio n. 13
0
 /**
  * Returns the entries for the current page for this view.
  *
  * @return \Illuminate\Pagination\LengthAwarePaginator paginator containing the entries for the page, sorted/ordered or not.
  */
 public function getPaginatedEntries()
 {
     // Gets all the entries, sensitive to whether we're sorting for this request.
     $allEntries = $this->getEntriesSortable();
     $page = Paginator::resolveCurrentPage('page');
     // Returns the number of entries perpage, defined by Model#getPerPage
     $perPage = $allEntries->first()->getPerPage();
     // If the page number is beyond the number of pages, get it back to the last page.
     while (($page - 1) * $perPage > count($allEntries)) {
         $page -= 1;
     }
     // Return the subset of the entries for this page
     $entriesForPage = $allEntries->splice(($page - 1) * $perPage, $perPage);
     // Return the paginator for this subset.
     $entriesPaginator = new LengthAwarePaginator($entriesForPage, $this->getEntries()->first()->toBase()->getCountForPagination(), $perPage, $page, ['path' => Paginator::resolveCurrentPath(), 'pageName' => 'page']);
     // If we're ordering, append that to the links
     if ($this->getSortOrder()) {
         $entriesPaginator->appends(['order' => Request::get('order')]);
     }
     // If we're sorting, append that to the links
     if ($this->isSorting()) {
         $entriesPaginator->appends(['sort' => $this->getSortKey()]);
     }
     return $entriesPaginator;
 }
 /**
  * Get the error messages for the defined validation rules.
  *
  * @return array
  */
 public function messages()
 {
     $parent_messeges = parent::messages();
     $my_messeges = [];
     $messeges = array_merge($parent_messeges, $my_messeges);
     return $messeges;
 }
 /**
  * Get the validation rules that apply to the request.
  *
  * @return array
  */
 public function rules()
 {
     if (Request::segment(3) == 'create') {
         $this->rules['file_name'] .= '|required';
     }
     return $this->rules;
 }
 /**
  * @param                      $id
  * @param Request              $request
  * @param BudgetRequestManager $budgetRequestManager
  * @return mixed
  */
 public function update($id, Request $request, BudgetRequestManager $budgetRequestManager)
 {
     $activityData = $this->activityManager->getActivityData($id);
     if (Gate::denies('ownership', $activityData)) {
         return redirect()->back()->withResponse($this->getNoPrivilegesMessage());
     }
     $this->authorizeByRequestType($activityData, 'budget');
     $budget = $request->all();
     if ($this->budgetManager->update($budget, $activityData)) {
         $this->activityManager->resetActivityWorkflow($id);
         $response = ['type' => 'success', 'code' => ['updated', ['name' => 'Budget']]];
         return redirect()->to(sprintf('/activity/%s', $id))->withResponse($response);
     }
     $response = ['type' => 'danger', 'code' => ['update_failed', ['name' => 'Budget']]];
     return redirect()->back()->withInput()->withResponse($response);
 }
 /**
  * Get the error messages for the defined validation rules.
  *
  * @return array
  */
 public function messages()
 {
     $parent_messeges = parent::messages();
     $my_messeges = ['fecha_ini.required' => 'Es necesario una fecha de inicio estimativa de la temporada, sobre todo para determinar el/los año/s que abarca la misma.', 'fecha_ini.before' => 'La fecha de inicio debe ser del año corriente o anterior al mismo.', 'fecha_ini.before_equal' => 'La fecha de inicio debe ser igual o anterior a la fecha de finalización del temporada.', 'fecha_fin.required' => 'Es necesario una fecha de finalización estimativa de la temporada, sobre todo para determinar el/los año/s que abarca la misma.', 'fecha_fin.after_equal' => 'La fecha de finalización debe ser igual o posterior a la fecha de inicio del temporada.'];
     $messeges = array_merge($parent_messeges, $my_messeges);
     return $messeges;
 }
Esempio n. 18
0
 /**
  * Get the validation rules that apply to the request.
  *
  * @return array
  */
 public function rules()
 {
     $tipo_documento_valor = Request::get('per_dcmto_tipo');
     $doc_numero = 'required';
     $per_dcmto_tipo = 'required';
     $per_ruc = 'sometimes';
     if (Request::get('per_tipo') == '0002') {
         $per_ruc = 'required';
     }
     if ($tipo_documento_valor == '0001') {
         $doc_numero = 'required|numeric|digits:8|unique:persona,per_dcmto_numero';
     } else {
         if ($tipo_documento_valor == '0002') {
             $doc_numero = 'required|max:12';
         } else {
             if ($tipo_documento_valor == '0003') {
                 $doc_numero = 'required|numeric|digits:11';
             } else {
                 if ($tipo_documento_valor == '0006' || $tipo_documento_valor == '0004' || $tipo_documento_valor == '0005') {
                     $doc_numero = 'required|max:12';
                 }
             }
         }
     }
     if (Request::get('per_nacion') == '0002') {
         $per_dcmto_tipo = 'required|same:0002';
     }
     return ['per_tipo' => 'required', 'per_nacion' => 'sometimes|required', 'per_dcmto_tipo' => 'sometimes|' . $per_dcmto_tipo, 'per_dcmto_numero' => 'sometimes|' . $doc_numero, 'per_ape_paterno' => 'sometimes|required', 'per_ape_materno' => 'sometimes|required', 'per_nombre1' => 'sometimes|required', 'per_nombre2' => 'sometimes|sometimes', 'per_razon_social' => 'sometimes|required', 'per_ruc' => $per_ruc, 'per_direccion' => 'required', 'per_ubg_id' => 'required|numeric', 'per_direc_referencia' => 'required'];
 }
Esempio n. 19
0
 /**
  * Get the validation rules that apply to the request.
  *
  * @return array
  */
 public function rules()
 {
     $path = Request::path();
     $id = explode("/", $path);
     $id = $id[count($id) - 1];
     return ['name' => 'required|unique:events,name,' . $id . ',id', 'timelineDate' => 'required', 'tags' => 'required'];
 }
Esempio n. 20
0
 /**
  * Get the error messages for the defined validation rules.
  *
  * @return array
  */
 public function messages()
 {
     $parent_messeges = parent::messages();
     $my_messeges = ['fecha_ini.required' => 'Es necesario una fecha de inicio estimativa del torneo.', 'fecha_ini.before_equal' => 'La fecha de inicio debe ser igual o anterior a la fecha de finalización del torneo.', 'fecha_fin.required' => 'Es necesario una fecha de finalización estimativa del torneo.', 'fecha_fin.after_equal' => 'La fecha de finalización debe ser igual o posterior a la fecha de inicio del torneo.', 'division.unique_with' => 'Para esta división, es posible crear a lo sumo un torneo de cada tipo por temporada.', 'tipo_torneo.unique_with' => 'Para la división seleccionada, ya existe un torneo de este tipo en esta temporada.', 'grupo_1.required' => 'Se deben indicar los equipos que forman el grupo.', 'grupo_2.required' => 'Se deben indicar los equipos que forman el grupo.'];
     $messeges = array_merge($parent_messeges, $my_messeges);
     return $messeges;
 }
Esempio n. 21
0
 /**
  * Manipulate the input before performing validation
  *
  * @return Validator;
  */
 protected function getValidatorInstance()
 {
     // Set default values.
     collect(['project_id', 'estimatedDuration', 'start', 'minutes'])->each(function ($field) {
         if ($field === 'start') {
             $value = sprintf('%s %s', $this->input($field . 'Date', ''), $this->input($field . 'Time', ''));
             $value = new Carbon($value);
         }
         if ($field === 'project_id') {
             $value = $this->input($field, 0);
         }
         if ($field === 'estimatedDuration') {
             $value = $this->input($field, 0);
         }
         if ($field === 'minutes') {
             $value = 0;
             $start = $this->input('startTime', 0);
             $end = $this->input('endTime', 0);
             if ($start && $end) {
                 $value = (strtotime($end) - strtotime($start)) / 60;
             }
         }
         $this->merge([$field => $value]);
     });
     return parent::getValidatorInstance();
 }
Esempio n. 22
0
 /**
  * Overwrite the validation method
  * only needs to be triggered when certain properties are set.
  * This is to enable patch updates.
  *
  * @return
  */
 public function validate()
 {
     $input = request()->input();
     if ($this->validationRequired($input)) {
         return parent::validate();
     }
 }
Esempio n. 23
0
 /**
  * Get the validation rules that apply to the request.
  *
  * @return array
  */
 public function rules()
 {
     if (Request::ajax()) {
         return [];
     }
     return ['image[]' => 'image'];
 }
 public function update($id, Request $request, ConditionRequestManager $conditionRequestManager)
 {
     $activityData = $this->activityManager->getActivityData($id);
     if (Gate::denies('ownership', $activityData)) {
         return redirect()->back()->withResponse($this->getNoPrivilegesMessage());
     }
     $this->authorizeByRequestType($activityData, 'conditions');
     $condition = $request->except(['_token', '_method']);
     if ($this->conditionManager->update($condition, $activityData)) {
         $this->activityManager->resetActivityWorkflow($id);
         $response = ['type' => 'success', 'code' => ['updated', ['name' => 'Conditions']]];
         return redirect()->to(sprintf('/activity/%s', $id))->withResponse($response);
     }
     $response = ['type' => 'danger', 'code' => ['update_failed', ['name' => 'Related Activity']]];
     return redirect()->back()->withInput()->withResponse($response);
 }
 /**
  * updates activity recipient region
  * @param                               $id
  * @param Request                       $request
  * @param RecipientRegionRequestManager $recipientRegionRequestManager
  * @return \Illuminate\Http\RedirectResponse
  */
 public function update($id, Request $request, RecipientRegionRequestManager $recipientRegionRequestManager)
 {
     $activityData = $this->activityManager->getActivityData($id);
     if (Gate::denies('ownership', $activityData)) {
         return redirect()->back()->withResponse($this->getNoPrivilegesMessage());
     }
     $this->authorizeByRequestType($activityData, 'recipient_region');
     $activityTransactions = $this->transactionManager->getTransactions($id);
     $count = 0;
     if ($activityTransactions) {
         foreach ($activityTransactions as $transactions) {
             $transactionDetail = $transactions->transaction;
             removeEmptyValues($transactionDetail);
             if (!empty($transactionDetail['recipient_country']) || !empty($transactionDetail['recipient_region'])) {
                 $count++;
             }
         }
     }
     if ($count > 0) {
         $response = ['type' => 'warning', 'code' => ['message', ['message' => 'You cannot save Recipient Region in activity level because you have already saved recipient country or region in transaction level.']]];
         return redirect()->back()->withInput()->withResponse($response);
     }
     $recipientRegions = $request->all();
     foreach ($recipientRegions['recipient_region'] as &$recipientRegion) {
         $recipientRegion['region_vocabulary'] != '' ?: ($recipientRegion['region_vocabulary'] = '1');
     }
     if ($this->recipientRegionManager->update($recipientRegions, $activityData)) {
         $this->activityManager->resetActivityWorkflow($id);
         $response = ['type' => 'success', 'code' => ['updated', ['name' => 'Recipient Region']]];
         return redirect()->to(sprintf('/activity/%s', $id))->withResponse($response);
     }
     $response = ['type' => 'danger', 'code' => ['update_failed', ['name' => 'Recipient Region']]];
     return redirect()->back()->withInput()->withResponse($response);
 }
 /**
  * Get the validation rules that apply to the request.
  *
  * @return array
  */
 public function rules()
 {
     if (Request::get('old_password') != "" || Request::get('password') != "" || Request::get('password_confirmation') != "") {
         return ['old_password' => 'required|confirmed|min:6', 'password' => 'required|confirmed|min:6', 'password_confirmation' => 'required|confirmed|min:6'];
     }
     return [];
 }
 public function response(array $errors)
 {
     if ($this->ajax()) {
         return new JsonResponse($errors, 422);
     }
     return parent::response($errors);
 }
 public function messages()
 {
     $input = parent::all();
     $messages = ['doacoes.required' => 'Doação precisa ser informada', 'doacoes.array' => 'Doação precisa ser um conjunto'];
     /*
      * Verifica se foram passados endereços
      * Caso contrário devolver as regras
      */
     if (!isset($input['doacoes']) || !is_array($input['doacoes'])) {
         return $messages;
     }
     /*
      * Messages para validação dos doacoes(endereços)
      * @var array
      */
     $doacoesMessages = ['value.required' => 'Você precisa informar um valor', 'value.numeric' => 'O valor precisa ser numérico', 'value.min' => 'Valor mínimo :min'];
     $doacoes = $input['doacoes'];
     $newMessagens = [];
     foreach ($doacoes as $row => $address) {
         foreach ($doacoesMessages as $key => $value) {
             $newMessagens['doacoes.' . $row . '.' . $key] = $row + 1 . ': ' . $value;
         }
     }
     return array_merge($messages, $newMessagens);
 }
Esempio n. 29
0
 protected function failedValidation(Validator $validator)
 {
     if (config('app.debug') || Request::is("api/*")) {
         throw new ValidationException($validator);
     }
     return parent::failedValidation($validator);
 }
 /**
  * Get the proper failed validation response for the request.
  *
  * @param  array  $errors
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function response(array $errors)
 {
     if ($this->ajax() || $this->wantsJson()) {
         return new JsonResponse(['errors' => $errors, 'message' => '<i class="fa fa-exclamation-circle fa-lg"></i>' . trans('create-project-form.validation-error'), 'element' => Request::get('name')], 200);
     }
     return $this->redirector->to($this->getRedirectUrl())->withInput($this->except($this->dontFlash))->withErrors($errors, $this->errorBag);
 }