Laravel 4: Validierungsnachrichten aus dem Repository an den Controller übergeben

Ioc und Repositories kennenlernen und die letzte Hürde nehmen!

Angenommen, ich validiere Eingaben. Wie gebe ich Nachrichten vom Validator im Repository an den Controller zurück?

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(); ?????     
        }       
...

Mein UserController

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();
        }
    }
    ...
}

Laravel ist erst 1,5 Wochen alt.

Antworten auf die Frage(1)

Ihre Antwort auf die Frage