这里是我的验证请求:规则验证的Fileds [Laravel 5]
<?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"
];
}
}
而且在我的模型我有这样的:
public function apiUpdateComment(UpdateCommentRequest $request){
$comment = Comment::find(Input::get("order"));
$comment->text = Input::get('comment');
if($comment->save()){
return 'success';
}
}
这的Fileds我需要验证agins规则阵列:
array(
'comment' => Input::get('comment'),
'projectID' => Input::get('projectID'),
'order' => Input::get("order"),
'level' => Input::get("level"),
);
我需要检查所有规则是否正常,然后更新评论......任何人都可以提供帮助吗?
我不明白这个问题。如果你传递了一个Request对象,那么只有在规则()被传递时才会通过请求。所以''apiUpdateComment'只会在UpdateCommentRequest-> rules()返回true时运行。 – dotty