1
저는 Laravel과 협력 중이며 컨트롤러에서 유효성 검사를 구현하기로 결정한 것으로 보입니다. 내가 물어보고 싶은 것은 컨트롤러에 지저분하지 않도록 내가 만든 객체에 게시 된 입력 필드를 바인딩 할 수있는 일종의 bind
메서드가 있는지입니다.입력 양식에서 모델 바인딩
나는 코드에서 내가 원하는 것을 설명하려고 노력할 것이다. 훨씬 더 명확해질 것이라고 나는 생각한다.
내가 가진 내가 갖고 싶은
public function postRegister() {
$validation = Validator::make(Input::all(), array(
'email' => 'required|email',
'password' => 'required|min:6',
'name' => 'required|alpha',
'gender' => 'required|in:male,female'
));
if ($validation->fails()) {
Input::flashExcept('password');
return Redirect::to('register')->withErrors($validation)->withInput();
}
// Register user...
}
class UserRegisterDto {
public $email;
public $password;
public $name;
public $gender;
protected $errors;
public function isValid() {
// Validate it here, set errors if there are some
return $validator->isValid();
}
public function getErrors() {
return $this->errors;
}
}
public function postRegister() {
$user = Input::bind('UserRegisterDto'); // This is made-up function, I wonder if something like this exists
if ($user->isValid()) {
// Register user...
}
}
흠, 잘 보이지만 'save'기능에 대해 혼란스러워합니다. 만약 내가 MySQL을 사용하지 않고 Cassandra를 저장하기 때문에 커스텀 저장소를 사용하고 있다면 어떻게 될까? – sed
모르겠다, 미안. 나는 그것을 MySQL과 함께 사용한다. – chris342423