dimanche 27 septembre 2015

Validation request with Laravel 5

I am trying to make validation with Laravel 5 on right way:

Here is my working code in model:

public function apiAddNewComment() {
        if (Input::get("task") == 'addComment') {
            $user = Auth::id();
            $inputs = array(
                'comment' => Input::get('comment'),
                'projectID' => Input::get('projectID'),
                'order' => Input::get("order"),
                'level' => Input::get("level"),
            );
            $rules = array(
                'comment' => 'required|between:15,600',
                'projectID' => "required|exists:project_group,project_id,user_id,$user|numeric",
                'order' => "required|numeric",
                'level' => "required|numeric"
            );

            $validator = Validator::make($inputs, $rules);
            if ($validator->fails()) {
                return json_encode(array('err' => true, 'errors' => $validator->messages()->all()));
            } else {
                return $this->createNewComment();
            }
        }
    }

here is my controller:

public function update($id, Comment $update)
    {
                return $update->apiUpdateComment();

    }

How can I make validation with request?

And can someone explain me how this method works inside request:

public function authorize()
    {
        return false;
    }

?



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/1JwQ7gd
via IFTTT

Aucun commentaire:

Enregistrer un commentaire