2
Ioc 및 저장소에 대해 배우고 마지막 장애물로 붙어 있습니다!Laravel 4 : 저장소에서 컨트롤러로 얻은 유효성 검사 메시지를 전달하십시오.
입력의 유효성을 검사한다고 가정하면 저장소의 유효성 검사기에서 컨트롤러로 메시지를 어떻게 다시 전달합니까?
UserRepository
interface UserRepository {
public function all();
public function create($input);
public function findById($id);
}
Sentry2UserRepository
class Sentry2UserRepository implements UserRepository {
...
public function create($input) {
$validation = Validator::make($input, User::$rules);
if ($validation->passes()) {
Sentry::createUser(array_except($input, ['password_confirmation']));
// Put something here to tell controller that user has been successfully been created
return true;
}
else {
// pass back to controller that validation has failed
// with messages
return $validation->messages(); ?????
}
...
Laravel에
UserController extends BaseController {
...
public function postRegister() {
$input['first_name'] = Input::get('first_name');
$input['last_name'] = Input::get('last_name');
$input['email'] = Input::get('email');
$input['password'] = Input::get('password');
$input['password_confirmation'] = Input::get('password_confirmation');
// Something like
if ($this->user->create($input)) {
Session::flash('success', 'Successfully registered');
return Redirect::to('/');
}
else {
Session::flash('error', 'There were errors in your submission');
return Redirect::to('user/login')->withErrors()->withInput();
}
}
...
}
1.5 주 내 UserController 그렇게 나를 쉽게 이동하시기 바랍니다.