vendredi 3 mai 2019

How to add username in welcome email after registration?

I've been searching everywhere for a solution to my issue. I've created a welcome email, created the Mailable, Controller, and View. But for some reason, the $user isn't showing in the email itself. It's blank. Am I missing something?

Mailable

<?php

namespace App\Http\Mail;

use App\User;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Contracts\Queue\ShouldQueue;


class Welcome extends Mailable
{
    use Queueable, SerializesModels;

    public $user; 
    /**
    * @return void
    */
    public function _construct(User $user)
    {
        $this->user = $user;
    }

    /**
    *@return $this
    */
    public function build()
    {
        return $this->view('emails.welcome')->subject('Welcome to');
    }
}

Controller

<?php

namespace App\Http\Controllers\Auth;

use Mail;
use App\User;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Validator;
use Illuminate\Foundation\Auth\RegistersUsers;
use Illuminate\Support\Facades\Auth;
use App\Http\Mail\Welcome;



class RegisterController extends Controller
{
    /*
    |--------------------------------------------------------------------------
    | Register Controller
    |--------------------------------------------------------------------------
    |
    | This controller handles the registration of new users as well as their
    | validation and creation. By default this controller uses a trait to
    | provide this functionality without requiring any additional code.
    |
    */

    use RegistersUsers;

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

    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->middleware('guest');
    }

    /**
     * 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, [
            'first_name' => 'required|max:255',
            'last_name' => 'required|max:255',
            'email' => 'required|email|max:255|unique:users',
            'mobile' => 'required',
            'password' => 'required|min:6|confirmed',
        ]);
    }

    /**
     * Create a new user instance after a valid registration.
     *
     * @param  array  $data
     * @return User
     */
    protected function create(array $data)
    {
        $user = User::create([
                            'first_name' => $data['first_name'],
                            'last_name' => $data['last_name'],
                            'email' => $data['email'],
                            'mobile' => $data['mobile'],
                            'password' => bcrypt($data['password']),
                            'payment_mode' => 'CASH',
                            ]);



        Mail::to($data['email'])->send(new Welcome($user));

        return $user;
        // send welcome email here
    }


    /**
     * Show the application registration form.
     *
     * @return \Illuminate\Http\Response
     */

    public function showRegistrationForm()
    {

        return view('user.auth.register');
    }

}

View (shortened to show problem)

Welcome 


As was mentioned, everything passes successfully, however, in the email itself, the name of the user is blank. Please help!



from Newest questions tagged laravel-5 - Stack Overflow http://bit.ly/2ZUiNkz
via IFTTT

Aucun commentaire:

Enregistrer un commentaire