User registration email confirmation issue

Posted 2 years ago by steveperrycreative

I've been following this tutorial on adding user registration email confirmation but instead of creating my own registration controllers I'm using an amended version of Laravel's auth controllers, bringing it inline with Jeffrey's custom version.

However when a user registers I receive the following error:

ErrorException in AuthController.php line 67:
Argument 2 passed to Prolinked\Http\Controllers\Auth\AuthController::create() must be an instance of Prolinked\Mailers\AppMailer, none given, called in /Users/steve/Server/jasoncampbell/vendor/laravel/framework/src/Illuminate/Foundation/Auth/RegistersUsers.php on line 59 and defined

Which I'd kind of expect but then Jeffery's version is the same and as far as I can tell his route isn't passing a 2nd argument through either but he is not getting this error. Am I missing something from somewhere else perhaps?

My AuthController is:

<?php

namespace Prolinked\Http\Controllers\Auth;

use Validator;
use Prolinked\User;
use Prolinked\Mailers\AppMailer;
use Prolinked\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\ThrottlesLogins;
use Illuminate\Foundation\Auth\AuthenticatesAndRegistersUsers;

class AuthController extends Controller
{
    /*
    |--------------------------------------------------------------------------
    | Registration & Login Controller
    |--------------------------------------------------------------------------
    |
    | This controller handles the registration of new users, as well as the
    | authentication of existing users. By default, this controller uses
    | a simple trait to add these behaviors. Why don't you explore it?
    |
    */

    use AuthenticatesAndRegistersUsers, ThrottlesLogins;

    /**
     * Where to redirect users after login / registration.
     *
     * @var string
     */
    protected $redirectTo = '/';

    /**
     * Create a new authentication controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->middleware('guest', ['except' => 'logout']);
    }

    /**
     * Get a validator for an incoming registration request.
     *
     * @param  array  $data
     * @return \Illuminate\Contracts\Validation\Validator
     */
    protected function validator(array $data)
    {
        return Validator::make($data, [
            'firstname' => 'required|max:255',
            'lastname' => 'required|max:255',
            'email' => 'required|email|max:255|unique:users',
            'password' => 'required|confirmed|min:6',
        ]);
    }

    /**
     * Create a new user instance after a valid registration.
     *
     * @param  array  $data
     * @param  AppMailer  $mailer
     * @return User
     */
    protected function create(array $data, AppMailer $mailer)
    {
        $user = User::create([
            'firstname' => $data['firstname'],
            'lastname' => $data['lastname'],
            'email' => $data['email'],
            'password' => bcrypt($data['password']),
        ]);

        $mailer->sendEmailConfirmationTo($user);

        flash('Please confirm your email address.');

        return redirect()->back();
    }

    /**
     * Listen for our user creation and add our token during that process.
     */
    public static function boot()
    {
        parent::boot();

        static::creating(function($user) {
            $user->token = str_random(30);
        });
    }
}

Let me know if you need to see any other code.

Please sign in or create an account to participate in this conversation.

Laracasts Mascot

Hi, Have We Met Yet?

Did you know that, in addition to the forum, Laracasts includes well over 1000 lessons on modern web development? All for the price of one lunch out per month.

Sign Me Up

Channels

Reply to

Use Markdown with GitHub-flavored code blocks.