Ejemplo n.º 1
0
 /**
  * Validates current attributes against rules
  */
 public function validate($model = null)
 {
     if (isset($this->attributes['created_at']) && isset($this->attributes[$this->primaryKey])) {
         foreach ($this->rules as $key => $rule) {
             if (strpos($rule, 'unique:') !== false) {
                 $rulesCol = explode('|', $rule);
                 foreach ($rulesCol as $key2 => $val) {
                     if (starts_with($rulesCol[$key2], 'unique:')) {
                         $rulesCol[$key2] .= ',' . $objAux->{$this->primaryKey} . ',' . $this->primaryKey;
                     }
                 }
                 $this->rules[$key] = implode('|', $rulesCol);
             }
         }
     }
     $v = $this->validator->make($this->attributes, $this->rules);
     $v->setAttributeNames($this->getPrettyFields());
     if ($v->passes() && $this->verificarConcurrencia()) {
         $this->afterValidate();
         return true;
     }
     $this->errors->merge($v->messages());
     return false;
 }
Ejemplo n.º 2
0
 /**
  * Set error message bag.
  *
  * @param \Illuminate\Support\MessageBag
  *
  * @return void
  */
 protected function setErrors($errors)
 {
     $this->errors->merge($errors->toArray());
 }
Ejemplo n.º 3
0
 public function createPost($subtitle)
 {
     $errorMessages = new Illuminate\Support\MessageBag();
     if (Subtitle::where('slug', $subtitle)->exists()) {
         $subtitle = Subtitle::where('slug', $subtitle)->first();
         if ($subtitle->active == 1 || Auth::user()->hasRole('admin')) {
             if (DB::Table('user_subtitle')->where('user_id', Auth::user()->id)->where('subtitle_id', $subtitle->id)->exists()) {
                 $rules = ["title" => "required|min:9", "link" => "url"];
                 $inputs = Input::all();
                 $validator = Validator::make($inputs, $rules);
                 if ($validator->passes() && (Input::has('link') || Input::has('content'))) {
                     $link = null;
                     $post = new Post();
                     $post->title = Input::get('title');
                     $post->content = Input::get('content');
                     if (Input::get('link') != null && filter_var(Input::get('link'), FILTER_VALIDATE_URL)) {
                         $link = Input::get('link');
                     }
                     $post->isLink = $link;
                     $post->isComment = 0;
                     if (DB::Table('user_subtitle')->where('subtitle_id', $subtitle->id)->where('user_id', Auth::user()->id)->where('isAdmin', '!=', 0)->exists()) {
                         $post->publish = 1;
                     } else {
                         $post->publish = 0;
                         Event::fire('new_post', [$subtitle->id, Auth::user()->username, Input::get('title')]);
                     }
                     $post->subtitle_id = $subtitle->id;
                     $post->user_id = Auth::user()->id;
                     $post->save();
                     return Redirect::route('subtitle', $subtitle->slug);
                 }
                 if (!(Input::has('link') || Input::has('content'))) {
                     $errorMessages->add("required", "Link veya İçerik boş bırakılamaz.Lütfen ikisinden birini doldurunuz!");
                 }
                 if ($validator->fails()) {
                     $errorMessages->merge($validator->errors()->toArray());
                 }
                 return Redirect::back()->with(['errors' => $errorMessages])->withInput();
             }
             return Redirect::route('subtitle', $subtitle->slug);
         }
         App::abort(404);
     }
     App::abort(404);
 }