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

Format and run tests0:06

Okay, ladies and gentlemen, I think it's time to start wrapping up. It's going a bit long, don't you think? So let's finish up by running Composer Run format. Let's run our test suites, make any fixes that we need to, and then push it up to Forge. And then finally make a change to demonstrate how you can perform an update, push it to Forge, and then immediately see the results in production. Let's get going. So to start,

and then immediately see the results in production. Let's get going. So to start, I'm gonna run a composer run format. Alright, just a handful of changes there. It looks like it's switched to a short closure. That's fine. Uh, next, let's run our test suites. So I can do pest or again, there's a PHP Artisan test command you can run. Um, ooh, we have one issue. I, we changed our feature test name,

Um, ooh, we have one issue. I, we changed our feature test name, but we didn't update the configuration all. We'll do that real quick. Should be, I think in peach P unit dot xml. Let's look for feature. Yeah, we could do a browser test suite for the situations where we want to perform our browser tests. Run test. There we go. Example, test, passing, passing, passing.

Run test. There we go. Example, test, passing, passing, passing. Uh oh, we got a little break. Maybe something's failing. Let's go to full screen. Log in test. All right, we'll take a look at that. Ah, okay. Okay. These are nice and easy. So for login and register, when we were done, we had hardcoded that we were redirected back to the homepage, but that's no longer the case. You'll remember we are redirected to the ideas page.

but that's no longer the case. You'll remember we are redirected to the ideas page. Okay, fair enough. Let's fix that. Let's go into registered user controller. When you're done, this redirects us to the ideas page. So let's go to route, or you should be able to say two routes idea index. Next, let's go into login test. And we should do the exact same thing. I'm sorry, login controller or sessions controller.

And we should do the exact same thing. I'm sorry, login controller or sessions controller. Sorry about that. And then redirect intended. Yeah, we'll just set this to route once again index or idea index. Alright, so now we can return to login test and update these. Assert path is, or assert route is idea that index and then registered test would do the same thing.

or assert route is idea that index and then registered test would do the same thing. Alright, so now we cross our fingers and we run it again. Pass, pass, pass, pass, pass, pass, pass, pass. It works. Uh, that's great. So I feel good about that. Of course we can commit with um, fixed tests. Next I wanna push this up to Laravel Forge and we already created that. So it's as simple as saying GI push. Alright, so that pushes it up to GitHub

Deploy to Forge2:41

So it's as simple as saying GI push. Alright, so that pushes it up to GitHub and then there's a hook that will pull that in with Forge and then it will perform a new deploy. Let's have a look. Alright, so if I log in immediately you can see it's performing a deploy and oh, actually it failed. So we must have had some kind of a compilation issue. That's okay. This sometimes happens at the beginning. Let's scroll and see where the bug was.

Fix production database config3:03

That's okay. This sometimes happens at the beginning. Let's scroll and see where the bug was. Um, running migrations, syntax error column links can't have a default. Val. So here's the issue. We are using SQ light locally, but in production it's defaulting to my SQL and the rules are slightly different. So in this case, the way we set a default value for links won't work. Um, I just wanna use SQ light in production,

value for links won't work. Um, I just wanna use SQ light in production, so I'm gonna fix that. And here's how. Let's go into my sites. This one, settings down to my environment. Scroll down and let's reveal my environment file. Don't worry, I'm gonna delete this entire project when we're done. Let's scroll down to database and yeah, we're gonna use SQ light here.

Let's scroll down to database and yeah, we're gonna use SQ light here. So now these uh, are not necessary. Good. Okay, so now let's deploy manually again and let's cross our fingers. It shouldn't take very long, but hopefully it'll work this time. Notice it's building my assets, running the migrations deployment complete. Okay, I think that worked. So back to overview.

running the migrations deployment complete. Okay, I think that worked. So back to overview. Let's visit my site and it seems to be working. Alright, so let's register. We'll do myself, Jeffrey Way, and it seems like everything's working exactly like we'd expect. Let's prepare an idea. And there we go. I think everything's just working. We can view it. This is what I'd expect.

I think everything's just working. We can view it. This is what I'd expect. I can edit, let's say react comma the Laravel way. Let's update it. That's reflected down here. This is great. I can edit my profile Jeffrey Jordan way. And we of course we know this will work because we have tests that prove it works. So congratulations. We together built an application and pushed it to production.

Add markdown descriptions4:49

We together built an application and pushed it to production. Okay, so now let's test out making a tiny change, pushing it up the forge, watching it, uh, perform a new deploy automatically and instantly my production site is updated. I think it would be nice if I visit my show page, if I scroll down to the description section. Yeah, assuming we include markdown in our description, well it should be formatted properly, right?

Yeah, assuming we include markdown in our description, well it should be formatted properly, right? I think that would be useful. So let's imagine that is a feature request that we are going to implement. Okay, well maybe we add a new accessor, something like formatted description. Well, if we go to our local, uh, server, let's open one up, scroll down and actually we don't have anything here. Perfect. Let's paste in a description for this course. And yeah, let's just add some random markdown stuff.

Perfect. Let's paste in a description for this course. And yeah, let's just add some random markdown stuff. Maybe make Tighten a link, stuff like that. All right, let's come down, update it. And of course it's gonna fail, right? Because we're now trying to access a formatted description property that doesn't exist. All right, let's fix that. So now I'm gonna go into our idea and I'll show you how to add an accessor.

All right, let's fix that. So now I'm gonna go into our idea and I'll show you how to add an accessor. So we'll do it maybe right here. An accessor is just kind of a fancy term for like a custom property or a computed property. Even I could say formatted description. And this is really important. I need to specify that it is a type or an attribute. So this one right here. So I will return attributes. We're gonna do a getter here.

So this one right here. So I will return attributes. We're gonna do a getter here. Basically, think of it like that. This is going to accept, uh, the value. If it is backed, it's not in this case. We'll have some attributes. And yeah, if I were to just grab the description. So this represents the, um, the attributes for the model, right? The title, the description, uh, status, stuff like that.

the attributes for the model, right? The title, the description, uh, status, stuff like that. So in this case, I'm just returning the description only and I'm assigning it to an accessor or like a custom property called formatted description. So if I were to come back now and give this a refresh, it will work. And we just get the description like we always do. Okay? But now we have a hook effectively where we can pass this off to markdown formatting.

But now we have a hook effectively where we can pass this off to markdown formatting. And as it turns out, Laravel has support for this. It includes some helpers here. I'm gonna wrap this string within Laravel string helper and then check this out. There's a markdown method right on it. So now if I were to come back and give it a refresh, we can see that yes, it has been formatted properly.

and give it a refresh, we can see that yes, it has been formatted properly. Now we are seeing the escaped HTML, and that's okay, but sure enough, we can see we have strong tags and anchor tag. This is what we want. Okay, so check this out, we'll go back to the show page. And now let's switch to full screen. So yeah, we want no formatting, so let's redo it and we'll say, uh, with the bangs

So yeah, we want no formatting, so let's redo it and we'll say, uh, with the bangs and we'll say idea formatted, right? Don't escape the H TM L. And then also real quick, while I'm here, the card defaults to an anchor. But now this could contain all sorts of things that don't go within an anchor. So yeah, we're just going to overwrite is so we'll say this is a simple div, come back, refresh.

So yeah, we're just going to overwrite is so we'll say this is a simple div, come back, refresh. And there we go. Okay, so now, yes, I can see the formatting here. I can see that this is a link that takes me to Tighten's website. Um, but it's not necessarily formatted overly nicely. There's not even spaces in between the paragraphs. So what I'll do is I do know that Tailwind includes a pros class.

So what I'll do is I do know that Tailwind includes a pros class. If we wanna pull in, uh, a little plugin, it's their, uh, typography plugin. Alright, so let's grab that. We can do NPM install, uh, tailwind CSS slash typography, and then we just have to register it as a plugin. And I can do that with an app CSS right here. So plugin and I'll reference that path and that should do it.

So plugin and I'll reference that path and that should do it. So now we get some free, um, formatting out of the box. There we go. But it's formatting, but it looks like we have a weird thing right here where I notice it's using black there. I think that's because it's assuming a light theme by default, and we can invert that. So let's go to the show page. And I think it's, what is it? Pros invert. I think this will do it. There we go.

So let's go to the show page. And I think it's, what is it? Pros invert. I think this will do it. There we go. And now we have some nice markdown formatting. Pretty cool, right? So if we edit, let's say this is great, now we can add more and even bulleted lists. All right, we've made some changes, we update and that should be reflected. This is great and pretty simple to implement. If you think about it, if you want,

Test and redeploy feature9:15

This is great and pretty simple to implement. If you think about it, if you want, we can even take 30 seconds and write a test for it. I'm gonna go to my unit test or my model test and we can say, yeah, right here. It can format a description using markdown down. All right, so let's do this. Um, let's just manually build up an idea. Idea equals new idea. And I'll set the description to hello

Idea equals new idea. And I'll set the description to hello and then a star and world. Okay, so now if I were to die and dump the formatted description, let's take a look and sure enough, we get the formatted version. And I'm just gonna, I'm just gonna steal this and paste it in. So now I can say, expect idea, formatted description, and I'll paste it in.

So now I can say, expect idea, formatted description, and I'll paste it in. All right, give it a run. Uh oh, it fails. This is because, uh, two B is, yeah, let's just do two equal, double give it a run. And now that one passes as well. Okay, so let's bring up our console. Let's do a get status. Here's our changes. I'll do a composer run format. All right, uh, anyways, looks good. It also runs pints. I will add everything to the staging area

All right, uh, anyways, looks good. It also runs pints. I will add everything to the staging area and we will commit with ad support for markdown formatting. I'm gonna push it up to production again, that goes up to GitHub. Uh, a hook sends it to Forge. Forge performs a deploy, and our changes should be reflected literally within 10 or 15 seconds. All right, so I can see it just deployed. So let's view it.

within 10 or 15 seconds. All right, so I can see it just deployed. So let's view it. I'll sign in. Alright, we're in. So now let's update the description to see if the markdown is working. Yep, I already, I can see it formatting in place. Let's edit and add some bold text and bullet points like so. Yep, we have our links, our strong tags. Looks good. Updates. Scroll down. And now that is being reflected.

Yep, we have our links, our strong tags. Looks good. Updates. Scroll down. And now that is being reflected. So congratulations. We have now pushed to production and implemented our first feature request.

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