dimanche 27 septembre 2015

Validation fileds from ajax request [Laravel 5]

Here is my validation request :rules

<?php

namespace App\Http\Requests;

use App\Http\Requests\Request;
use Illuminate\Support\Facades\Auth;

class UpdateCommentRequest extends Request {

    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize() {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules() {
        $user = Auth::user()->id;
        return [
            'comment' => 'required|between:15,600',
            'projectID' => "required|exists:project_group,project_id,user_id,$user|numeric",
            'order' => "required|numeric",
            'level' => "required|numeric"
        ];
    }

}

And in my model I have like this:

public function apiUpdateComment(UpdateCommentRequest $request){

    $comment = Comment::find(Input::get("order"));
    $comment->text = Input::get('comment');
    if($comment->save()){
        return 'success';
    }

 }

This fileds I need to validate agins rules array:

    array(
        'comment' => Input::get('comment'),
        'projectID' => Input::get('projectID'),
        'order' => Input::get("order"),
        'level' => Input::get("level"),
    );

I need to check if all rules are ok and then update comment... Anyone can help?



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

Aucun commentaire:

Enregistrer un commentaire