Недавно я обновил Laravel 5.3
от Laravel 5.2
, после чего я нашел несколько вопросов проверки. Одна из странных проблем связана с правилом required_without
i.e. отлично работает с laravel 5.2.Laravel 5.3 validation issue
route
является:
Route::post('chats/create','[email protected]');
Внутри контроллера, я определил метод insertMessage()
как:
public function insertMessage(Request $request){
$error = false;
$result = array();
$responsecode = 200;
$input = $request->all();
$validator = Validator::make(
array(
"patient_id" => $input["patient_id"],
"chat_id" => !empty($input["chat_id"]) ? $input["chat_id"] : null,
"sender_id"=> $input["sender_id"],
"image" => $request->hasFile('file') ? $request->file('file') : null,
"content" => !empty($input["content"]) ? $input["content"] : null
),
array(
"patient_id" => "required|exists:users,id,user_type,patient",
"chat_id" => "sometimes|nullable|exists:chats,id",
"sender_id"=>"required|exists:users,id",
"image" => "required_without:content|image",
"content" => "required_without:image"
)
);
if ($validator->passes()){
try {
DB::beginTransaction();
//Some operations
}
catch(\Exception $e){
//Some operations
}
}
//Finally return the response
return response()->json(array(
'error' => $error,
'input_data' => $result),
$responsecode
);
}
и запрос я делаю с помощью пост-человека, как:
Запрос он aders Authorization
и custom header
, нет content-type
Заголовок есть. И response
я получаю:
{
"error": true,
"input_data": {
"error_message": "The image must be an image. "
}
}
Почему это требует изображение, если content
поле присутствует там в данных request
?
Используя заявление dd($input);
я могу получить почтовые данные, как:
array:4 [
"patient_id" => "3"
"content" => "Hello"
"sender_id" => "1"
"sender_name" => "System Admin"
]