3
사용자 설정을 지정하는 API가 있습니다. 입력 값이 모두 필수가 아니기 때문에 값이 존재하는지 먼저 확인한 다음 Null 값을 피하기 위해 모델 특성을 설정하려고합니다.값을 설정하기 전에 요청 입력이 null이 아닌지 확인하십시오.
$this->InputValidator->validate($request, [
'firsname' => 'string',
'lastname' => 'string',
'email' => 'email',
'mobile_phone' => 'string',
'address' => 'string',
'language' => 'string',
'timezone' => 'string',
'nationality' => 'string',
'profile_photo' => 'url'
]);
$userInformation = new UserInformation([
'firstname' => $request->input('firstname'),
'lastname' => $request->input('lastname'),
'email' => $request->input('email'),
'mobile_phone' => $request->input('mobile_phone'),
'address' => $request->input('address'),
'profile_photo' => $request->input('profile_photo')
]);
$User->information()->save($userInformation);
입력 값 중 하나가 존재하지 않으면 특별히 모델에 전달하고 싶지 않습니다. 또한 내가 입력을 만들고 싶어 그나마
$ request-> has ('input')을 더 잘 사용하면 빈 문자열 및 null 값에서 작동합니다 (laravel 5.4에서 빈 문자열은 요청시 null로 변환 됨) –