Undefined variable: newsletter

Posted 1 year ago by muazzamazaz

<div class="form-group">
                            <div class="col-md-6 col-md-offset-4">
                                <div class="checkbox">
                                                                    
                                    <div class="form-check abc-checkbox">
    <input class="form-check-input" id="checkbox2" type="checkbox" name="newsletter" {{ old('newsletter') ? 'checked' : '' }} value=1>
    <label class="form-check-label" for="checkbox2">
     Email me newsletters
    </label>
  </div>

class User extends Authenticatable
{
    use Notifiable;

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
       // 'name', 'email', 'password',
       'name', 'email', 'password', 'provider', 'provider_id','newsletter'
    ]

class RegisterController extends Controller
{
......
protected function validator(array $data)
    {
        return Validator::make($data, [
            'name' => 'required|string|max:255',
            'email' => 'required|string|email|max:255|unique:users',
            'password' => 'required|string|min:6|confirmed',
            'newsletter' => 'required',
        ]);
    }

    /**
     * Create a new user instance after a valid registration.
     *
     * @param  array  $data
     * @return \App\User
     */
    protected function create(array $data)
    {   
        
        return User::create([
            'name' => $data['name'],
            'email' => $data['email'],
            'password' => bcrypt($data['password']),
            'newsletter' => $newsletter 
        ]);
        
    $user = User::create($request->all());
        $mailer->sendEmailConfirmationTo($user);
        flash('Please confirm your email address.');
        return redirect()->back();
    }

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