GithubHelp home page GithubHelp logo

Comments (3)

prenna avatar prenna commented on August 16, 2024

I'll see if I can figure it out after watching the Mailables lesson on Laracasts.

from centaur.

prenna avatar prenna commented on August 16, 2024

Okay, got it sorted.

  1. Make a mailable with a suitable name e.g.
php artisan make:mail CentaurWelcomeEmail
  1. Edit App\Mail\CentaurWelcomeEmail to look like this:
<?php

namespace App\Mail;

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

class CentaurWelcomeEmail extends Mailable
{
    use Queueable, SerializesModels;
    
    public $email;
    public $code;
    
    /**
     * Create a new message instance.
     *
     * @return void
     */
    public function __construct($email, $code)
    {
        $this->email = $email;
        $this->code = $code;
    }

    /**
     * Build the message.
     *
     * @return $this
     */
    public function build()
    {
        return $this->
            ->subject('Your account has been created!')
            ->view('centaur.email.welcome');
    }
}
  1. In App\Http\Controllers\UserController and App\Http\Controllers\Auth\RegistrationController replace the following (in the store method and postRegister method respectively)
            Mail::queue(
                'centaur.email.welcome',
                ['code' => $code, 'email' => $email],
                function ($message) use ($email) {
                    $message->to($email)
                        ->subject('Your account has been created');
                }
            );

with the following

            Mail::to($email)->queue(new CentaurWelcomeEmail($email, $code));

(how nice does that look)

  1. be sure to make sure you add the following to the top of each controller
use App\Mail\CentaurWelcomeEmail;
  1. Do similar for any other existing mail sent by controllers (poss just reset email - haven't looked yet).

  2. View mailable documentation here https://laravel.com/docs/5.4/mail#queueing-mail for any other preferential changes.

Would be nice for new users when this is set up by default.

from centaur.

rydurham avatar rydurham commented on August 16, 2024

Thanks for your pull request! I made some additional tweaks to the namespace references and the test assertions to get the tests passing. Your mailables have been included in v4.0.2.

from centaur.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.