這裏是我的驗證請求:規則驗證的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