2

I have a registration code:

public function postRegister(Request $request, AppMailer $mailer) {
    $post = $request->all();

    $rules = [
        'email' => 'required|email|unique:users|confirmed|max:255',
        'password' => 'required|confirmed|min:8|max:50',
    ];
    $v = \Validator::make($post, $rules);

    if($v->fails())
        return "fail!";

    $data = [
        'email' => $post['email'],
        'password' => \Hash::make($post['password'])
    ];
    $user = User::create($data);
    $mailer->sendEmailConfirmationTo($user);

    return "account created!";
}

But, after the registration, laravel makes auto login. How can i disable the auto login?

  • You have to give us more context on this snippet of code you just posted. Laravel's default registration system automatically logs you in, but the snippet you posted does not do that. – Thomas Kim Apr 19 '16 at 16:24
  • @ThomasKim I edited the post –  Apr 19 '16 at 16:38
  • Possible duplicate of [How to disable auto login on register in Laravel 5?](http://stackoverflow.com/questions/31478303/how-to-disable-auto-login-on-register-in-laravel-5) – Claudio King Apr 19 '16 at 16:58
  • Are you sure the route is calling this method? The default register route hits the `register` method rather than the `postRegister` method. – Thomas Kim Apr 19 '16 at 18:52

2 Answers2

1

I think that the fastest way to do that is:

$user = User::create($data);
$mailer->sendEmailConfirmationTo($user);
Auth::logout(); //logout please!
return "account created!";

For the slower one, look at this question:

How to disable auto login on register in Laravel 5?

Community
  • 1
  • 1
Claudio King
  • 1,606
  • 1
  • 10
  • 12
1

If you are using Laravel 5.2 try with this function inside your AuthController

public function register(Request $request)
{
    $validator = $this->validator($request->all());
    if ($validator->fails()) {
        $this->throwValidationException(
          $request, $validator
        );
    }

    $user = $this->create($request->all());
    return redirect($this->redirectPath());
}

Make sure to add this to the top of your AuthController:

use Illuminate\Http\Request;

Adan Archila
  • 323
  • 1
  • 4
  • 13