در حال بارگذاری ...

Creating Markdown Mailable0:00

Now, Laravel 5.3 introduced mailables. However, we can now use markdown for those mails. So let's create a welcome mail, and now I'm going to add this new markdown flag to specify a path for some boilerplate that Laravel is going to generate for me. We'll call this emails.welcome. Okay, so now you'll see that we have an app, mails.welcome class, but also if we scroll down to resources/views, we now have an emails folder with a bit of boilerplate here. Now, two things. Note that we're using markdown here, so I could say one, two, three, and Laravel is going to compile that down when we send the email. And next, we're also taking advantage of components, which we learned about in the last episode. So let's give this a shot. We're going to go to our welcome email, and now if we scroll down to the build method, in 5.3 you would call the view method. But now we make a call to markdown if we want to use

Passing Data to Email0:43

We're going to go to our welcome email, and now if we scroll down to the build method, in 5.3 you would call the view method. But now we make a call to markdown if we want to use markdown mail. Now, let's imagine here that we want to accept a User, and I'll make that public. And then within our template, we'll just say, hello, username. Remember, with mailables, any public property you define here will immediately be available to the template. All right, next, let's scroll down to our .env file, and we're going to use MailTrap here to review the email. So I will visit mailtrap.io. You can sign up for free. I already have an account using GitHub, and I will create a demo inbox. And now if I click through, we can grab our username and password. username, password, and we're all set. So let's give this a shot. php artisan tinker. We will set up a new welcome email, so new App\Mail\Welcome, and that will need a User,

Sending Test via MailTrap1:30

and password. Username, password, and we're all set. So let's give this a shot. php artisan tinker. We will set up a new WelcomeEmail, so new App\Mail\WelcomeEmail, and that will need a User, so I will just pass it the first one. Okay, next, we can say I'm going to send a mail to, once again, that User, and we'll fire off this WelcomeEmail. Okay, that's all done. So now if we switch back, we have our email, and take a look. Let's open this in a new tab. This is what you get, but you are able to use markdown to prepare this, which is really cool, I think. Now, just a quick 30-second overview of some of the things you can do. So yes, you can specify a custom button, like start browsing, and then send that to ericas.com. You can also use a few different components, like another one would be if you want a dedicated panel, which you can think of as sort of like a box. So let's spit out some lorem ipsum text there.

Using Markdown Components2:19

You can also use a few different components, like another one would be if you want a dedicated panel, which you can think of as sort of like a box. So let's spit out some lorem ipsum text there. Yeah, you get the basic idea. Now, you'll see that we do reference the name of the application, and this will be for the signature as well as the header. So you can go to config/app.php, and then update this as you need to. Okay, let's close this out and try it one more time. So we build up a welcome email, and then finally we fire off the mail. So let's go back to Chrome. Here's our new one, and you can see we've added our panel, and we have a link to the website. Very, very cool. Now, final note, if you want to customize the presentation here, of course you can. You can say php artisan vendor:publish, and if we leave it like that, it will publish everything. Otherwise, we can be specific that we want the

Publishing and Editing Mail Views3:03

the presentation here, of course you can. You can say php artisan vendor:publish, and if we leave it like that, it will publish everything. Otherwise, we can be specific that we want the Laravel mail tag. Okay, and you'll see that that directory was copied to our resources folder. So if we take a look now, here's our vendor mail, and now you can edit all of these to your heart's content. You can even set up a custom theme. So default.css, this is what's being inlined to what you see here. And in fact, if we review it, you'll see that those styles are inlined. But what you could also do is create your own theme. So you could go to config/mail.php, and if I scroll down, let's find theme. Yes, you can see the theme points to default, which is this, but you could also set up a Laracast specific theme, laracast.css, and then we could just grab this as a starting point and then modify it however we need to. So maybe we will update the header or something like

Creating a Custom Theme3:47

also set up a Laracast specific theme, laracast.css, and then we could just grab this as a starting point and then modify it however we need to. So maybe we will update the header or something like that. We'll give it a background color of orange, just so it stands out. Okay, so we've updated our custom theme. We're specifying that within our configuration. So let's give it another shot. Build up a welcome email, and then fire it off. So we should now have an orange background here, and we do. Doesn't look great, but of course, you can modify it however you want. And that's all there is to it.

دوست دارید گاهی خبرهای Laracasts را ایمیل کنیم؟