Laravelvideo· Sep 16, 2025· 2:03:16
Hi there and welcome to the Laravel boot camp. This course is meant to be your first look into what Laravel is and what it has to offer when you're building web applications from start to finish. But before we even start writing any code, why don't we take a look at what we're going to be building. So this is Chirper. It's a friendly micro blogging type platform where users can post little short messages. We'll call them chirps. And you can see what others are saying, edit, delete them. Everything you might expect from something like
this. You can think of it like your own little Twitter just with fewer billionaire buyouts. So, this is hosted on Laravel Cloud. That's chirper.laravel.cl.comcloud for a real online live demo. And throughout this course, we'll walk you through how to put your own version of Chirper on Laravel Cloud as well. So, we'll be building authentication, being able to sign in or register accounts. And when you do sign in, you have the ability to edit or delete past chirps.
But like you might have seen, you only have that ability for the ones that you've created once you've logged in. So artisans, let's get started and chirp. So everything that you've seen is what you'll be building as you follow along with this boot camp from start to finish. If this is your first time building anything with Laravel or even seen any Laravel code, well, you've come to the right place. By the end of this boot camp, you'll have a solid understanding of how to build a real working web application with Laravel from start to finish and what Laravel
gives you out of the box. So, are you ready? Let's start shipping and let's build your first app. Let's start by setting up your first Laravel project. To do that, we'll start at the documentation at laravel.com. So, whether you're on Mac OS, Windows, or Linux, Laravel.com's documentation has clean instructions and a oneline command that you can paste into your terminal to get started. What this does is if you don't have PHP and Composer installed or
even the Laravel installer, this will install all of that in one simple command for you. Since I already have it installed, I'm going to skip the step. One easy way to see if everything worked is if you type PHP-V for the version of PHP that we just installed or even the Laravel-V, which will say that, hey, you have the Laravel installer. And in this case, I have 5.17 up and running. Now I will note that if you did have PHP and composer installed
previously, you could use this composer global require Laravel installer command to get this up and running as well. After running that command, you might have to quit and restart your terminal session in order to make sure everything that it installed is available for you globally. I'll go ahead and do just that. And so we're ready to go. I have a code directory that I like to put all of my projects in, but you can run the Laravel installer wherever you see fit.
I'm going to type Laravel new and then I'm going to call this chirper. We're not going to use a starter kit for right now. And while we won't be touching testing in this course, I'm just going to leave it with the default options. Again, we're going to use the default options for this course. So, SQLite is perfect. And you guessed it, we'll stick with the default options. So, running npm install in order to install the JavaScript dependencies for our application. And look at that, the application is ready in the chirper directory. So, we're going to move into
that directory with cd chirper. I'm going to clear out this terminal. And you might have seen that last note. In order to get this application up and running, we can use composer rundev. What this does is it kickstarts the development process, the development server for us. So, not only do we have our assets ready to go at a specific vit port, but then we also have our app URL for this Laravel application. I'm going to open this up in our browser. And
there we go. We're using Laravel 12 for this current version of the Laravel Boot Camp. With our Laravel application up and running, why don't we take a look at the code that the Laravel installer generated for us, even without selecting a starter kit. I'm going to be using VS Code as my editor of choice for this boot camp. But the good thing is it doesn't really matter. You can use any text editor or IDE that you like. Laraveville works great with all of them. Some popular choices include things like VS Code and Cursor which
neatly both of which have their own extension specifically for Laravel. This is the Laravel official extension. It works great with VS Code or any kind of VS Code forks like Cursor. If you prefer a more dedicated IDE, PHP Storm is a favorite among PHP developers and Laravel developers. But no matter what you pick, you're set for a smooth ride. Even PHPstorm has its own Laravel idea
plugin which is free for users of PHP storm. Before we get any further, I do want to take a quick time out to talk about Laravel and AI. Laravel is designed to work beautifully with AI assistants. In fact, the framework includes Laravel Boost, which is a powerful tool that bridges this gap between AI coding agents and Laravel applications. It detects what is installed in your application and then
allows those AI assistants to then work with it effortlessly while providing documentation as well as just being able to interact with your Laravel application the way you expect you would interact with the Laravel application. So, while I'm not going to have any AI assistance or even AI uh autocomplete turned on for this course, AI and Laravel does make a fantastic pairing. And if that's something that you would
like to do, I would recommend checking out Laravel Boost, but it's not going to be an integral part of this course. You can ask AI to help explain some of these concepts and debug issues. And I might make notes of where Laravel boost helps when we're building out this application, but just remember the easiest way to learn is being able to write it out yourself or at least have a better understanding of if AI assistants are writing this for you. Um, how does
it actually work? Now, as we get back into it, I do want to give you a quick highle overview of the project structure that the Laravel installer generated for us. We have our chirper directory. That's where we uh installed this application. And in here we have app code. And this is where your PHP code. Things like models and controllers are going to go. We'll talk a little bit more about those as the course progresses. Then I want to direct your
attention to this resources directory. This is where your views are going to go. In this case, where does your HTML go? You can think of these blade templates as HTML with a little bit of extra magic and superpowers on top. And then we have this routes directory. This is where we can define our application's URLs or when a user hits a particular page in your application, what should
happen? And then lastly, this database folder. Now the neat thing about this directory is because we selected SQLite in the application installer we have a database specifically just as this one file database.sqlite SQLite. But in this directory is also where things like our migrations are going to go as well, telling our database what happens. And again, we'll dive into all of this at a later time throughout this course. I
just wanted to give a highle overview of all of this and what it actually looks like. The things that you're usually going to take time and spend time in within a Laravel application. All of this might look like a lot now, but you'll be navigating these folders with ease very soon. I just wanted to let you know that there's really only going to be a couple of them that we'll spend the majority of our time in. So, don't check out just yet. So, we have our application. We have it open in our text
editor. And then we also have our development server up and running to see any of the changes that we make. I think we're ready to get building. So when you first opened up that link, that URL that the server is running on, when we ran the composer rundev command, that's 127.0.0.1. This is on port 8000. You're greeted by Laravel's friendly default welcome page, at least for Laravel 12 at the time of
this recording. And when we take a look at our code, that's thanks to this route in routes, and that's that directory web.php. It looks like this. This little bit of code tells Laravel when someone visits, thanks to this route facade, when someone visits the homepage, the slash route, we're going to show them this welcome view. And again, since I'm using VS Code with the official Laravel
extension, I can have this option click to be able to follow that welcome view to this welcome.blade. This is where that web.php PHP route is saying when a user goes to slash or the root directory of your application, we're going to return the view that is welcome. And that's what this view looks like. Let's make some changes. Let's update this to um let's say the home
route. I'm going to save that. And because I have the VS Code extension, it's actually giving us an error right here in the editor that the view home is not found. And if we were to open up our application, we get that same server error. This view home is not found. So, what can we do about this? And again, if you're using the Laraveville VS Code extension, not only does it tell you that this view cannot be found, but it also gives you an easy way to fix this,
to create a new home.blade.php file. But we'll do that by hand for everyone following along. In our views directory, we're just going to create a new file. And I'm going to call this home.blade.php. Now, we're not going to get an error anymore, but if I was to go back, it's just a blank page. So, why don't we go ahead and create this home view? Now, I'm just going to paste in the entire code so that we can get this up and running as quickly as possible, and
we'll walk through it step by step. If you're following along on the Laravel learn page, you can find it below this lesson. If you're not following along on the laravel.com/learn page, that's a great place to find this code. Now, a couple things to note is that Blade is just HTML. We could have a whole script tag in here if we wanted to, or we could have a style tag.
Everything that you see in this file is just HTML. Blade just has a little bit of templating on top of that that we can get into in a little bit. Now for this application, we have a couple of things that we are giving you out of the box, even on top of what Laravel already provides just to make things a little bit easier and keep the focus on what Laravel does and how we can build applications with Laravel and less about
styling and everything like that. Laravel already gives us Tailwind CSS out of the box and it's set up for our application to use. So when I go into this home directory, what's happening is when we use this at vit directive, we are saying we want to use the app.css file and the app.js. And again, just to keep things as simple as possible, focusing on Laravel itself, we're
including Daisy UI as one of the links that we're bringing in mostly to be able to have uh some styles out of the box. It uses Tailwind CSS. So, we're just building on top of what Laravel already gives. You can see here that we have this data theme of Loi. That is Daisy UI. All right. Now that we have that saved in our code editor, if we go back to our browser, we should see the yes, now updated chirper. So, it's starting
to look a little bit better. But this is where all the fun actually begins. All right, we have this HTML file here, our home.blade.php. And you can imagine this would get a little bit complex because if we were to use additional pages like say a sign in or sign up page, we would copy everything and then add it to a new signin page and then change the things that we needed to change. But then if
something small changed, we needed to change on everything. This is where blade layouts or in this case a layout component that is a blade file. This is where those come into play. You can take your content from these views and then that gets injected into the layout via this special slot variable. It looks something like this. And so what we're going to do is we're going to create a new layout component to take everything
here, let's say everything in this main div, and push it into a slot. So any new page that uses that layout then automatically gets all of this extra stuff attached to it from the get- go. What we can do is in our resources folder in our views, we're going to create a new folder, a components folder. And in that components folder, this is what Laravel looks for. We're
going to create a new layout.blade.php. Now, for right now, I'm just going to copy all of this and put this in layout.blade.php. And in this main class, I'm going to take this out and add this slot variable. So that way any time we are using this layout.blade.php,
it's going to use all of this including the HTML document, the head, the vit, as well as any other additional things that we add to this file, and it's going to pass it in to this slot. So basically any other stuff that we add to a file in this layout will be put right here. So that's what we're going to do in home. Um we're just going to take all of this.
Actually, let's just copy this within the main div. I'm going to replace everything. We're going to say x dash layout. And then I'm going to paste everything in x layout. And this is wrapping this up. Now, Laravel knows to look for a layout in the views components directory. And you can see here that the Laravel extension automatically says that, hey, this is
valid. And so, if we were to look at our browser, we shouldn't see any change because we just kind of took this one file and made it into two files to make it more composable in the future. And yeah, we if we refreshed even, we still had and have this application looking exactly how we expect. We're going to do one more thing in our layout. We're going to make this title a little bit
more composable. instead of something that is hardcoded into this file. And we're actually going to use some PHP here to say, okay, if this title variable, and we'll get to what this looks like in a little bit. If it's set, let's use the title. If not, let's just revert to chirper. And what this is
going to do is now we can set this prop of title in our layout where we're using that in our home.blade.php. Okay, what does this look like? Well, now we have this x- slot variable allowed where we can pass it the title and say we're just going to use welcome. So, if I was to save this and go back to our browser, refresh here in the browser, we see that title, welcome
chirper. If I was to change this to something else such as hi there boot camp, we should see exactly the same thing. Yep, hi there boot camp chirper. I'm going to change it back to welcome. Next, to start setting up our application for a little bit more composibility in the future, we're going to add some styles to our app.css file. You can find these in the Laravel learn page for this course lesson. and
pasting this in. This is just a way for us to have a fade out animation. That way, we don't have to think about this later when we set up notifications. And this is Tailwind CSS's V4 way of doing this within an application. With all this in mind, we now have an application that is ready to start adding pages. We just have to use this X- layout in order to get everything that we would expect within our application. this nav, a
footer, and then a simple layout to be able to add things here. We're ready for the next lesson. All right, congratulations. You have your first Laravel application running locally. We used composer rundev to set up our local development server and then we used layouts to compose what the start of our application should look like. We haven't really touched Laravel just yet, but don't worry, we'll get
there. Laravel is about the whole package of an application from start to finish. But what good is an application if you only can see it in your browser on your machine? Why don't we get this chirper application live on the internet with Laravel cloud? It's the easiest way to deploy a Laravel application and it's made by Laravel itself. There's a few things that you'll need or at least knowledge of things that you'll need before we deploy a GitHub account. You
can create that free at github.com. um some basic git knowledge. We'll walk through those commands together and then your Laravel application from previous lessons. So you should have that ready to go. Now it's possible your machine does not have git installed if that's the case. Uh git-scm.com is probably the best resource in order to install git. All right, in our terminal in the directory of our
Laraveville Chirper application, we're going to initialize a new git repository. That's done with the get init command. That way, we have a repository ready for us to push to GitHub. What I'm going to do is add all of our files. We can do that by get add and then a period. And this adds everything to that git commit. And we're just going to do that. Get commit. And we're going to have a message of uh our
first Laravel app. And because we have git ignore set up for us out of the box within Laraveville, we don't have to worry about pushing something that shouldn't be pushed to github.com. Now on github.com, we're going to create a new Git repository. New repository. I'm going to create myself as the owner. And we're going to call this Chirper. You don't have to put a description if you don't want. And I'm going to make this
private for now. Create repository. All the other default settings should be fine. And GitHub gives us some commands that we are able to use. And this is what we want. So we're going to copy this. And in our terminal, paste that in. If we refresh that GitHub repository, we should see yes, there is all of our code ready to be deployed on Laravel Cloud. So I'm going to head to cloud.laravel.com.
If you don't have a Laravel cloud account already, you can sign up for one for free. It is free to get started. You do have to enter a credit card, which just means it is pay as you go. So, as much usage that your application uses, that's what you're going to be paying for. Now, we're going to make this as cheap as possible for you when you push this application, but this is just to show you how easy it is to get this up and running. and it's great to see your
application live out in the wild. I'm going to click new application and then you'll see any repositories that have been recently pushed to your GitHub account. And so that's what we want, Chirper. I'm going to select that and create the application. While there shouldn't be too much that you have to change here, if you are on the growth plan, the paid plan of Laravel Cloud, then your app cluster is not going to be
hibernated by default. You can see here that this is $5 per month in compute for these particular settings. Now, if you are on the starter plan, the pay as you go plan to sign up, then you will have hibernation enabled by default. I'm going to turn that on for this as well as turning it to 5 minutes. And what that will do is saying, hey, this could cost up to $5 a month if it doesn't
hibernate throughout the month. Feel free to change that hibernate after number to as low as you would like. That startup time is probably going to be around 30 seconds if no one has actually hit your application after it's been hibernating. Now, the only thing that we have to do is add a resource. And while we haven't used our database in our local environment, we're going to get a database up and running so that it's ready for us when we do push these changes into production. Right. Create
and connect a database. We can click create new database cluster. I'm going to use Laravel serverless Postgres just so we can hibernate this database because we're not going to be using it much and it's just a fun application. And then that way it costs less for us the user. We can select a specific region. I'm just going to select US East. And then we have dev. It's going to hibernate after 300 seconds. This database cluster will cost between $0
and $255 per month. And since this is just a fun application, you probably won't even get close to this number. If you did want to select the Laravel MySQL database, that is a flat fee. So the dev would be a flat fee of $6 per month. But again, just to get started, we're going to use the serverless Postgres. Now I'm going to click save and deploy. So now that we have a database configured, Laravel
cloud is going to deploy our application. the code that we have pushed to that GitHub repository. It's going to configure everything, install the dependencies, set up that database, and connect to it so that we're ready to go anytime we push any new changes to our GitHub repository. It's going to configure our web server so that this application is publicly accessible. And it's going to give us a domain, a URL that we can actually change as well.
While Airb Cloud deploys this fairly quickly, you can also see the progress in real time. And just like that, in 39 seconds, we have our application deployed. If I was to go to our environment, we would see that Chirper URL that's automatically generated for us. Clicking on that brings us to our application. And there we go. This is our application deployed to the cloud and it looks identical to our
development server. The neat part is Laravel Cloud has already set up this magic for us. So anytime we make any change and deploy it or push it to GitHub, Laravel Cloud will grab those changes and make that available for us in our public version. So why don't we do that right now in our code? I'm just going to add another line of code right here that says now this is live on the internet. And if we were to take a look at our local version, yes, we see this
is available. But what we're going to do in our terminal, we're going to say get status just so that we know, hey, there is something that needs to be pushed and changed. I'm going to add this new change and then commit it to say our first cloud auto deployment and we're going to push this change. So what Laravel Cloud is doing now is it's taking that change and then adding this to the new Laravel cloud deployment. We
can see that happen live at cloud.larville.com. You can see here our latest deployment is getting ready to be pushed up. I can go into Chirper and see that happening in real time as well. And then once this has completed again in just under a minute, we should be able to refresh our live page and see that change. It's as simple as that. So we've taken our code
and put it onto GitHub using the Git version control. It's there ready for deployment as well as safekeeping and collaboration. And then we push this code through that GitHub repository to Laravel cloud. It's a live application that now exists on the internet for your friends, family, and loved ones to see. And the great thing is because of those automatic deployments, anytime you push new changes to your GitHub repository,
more features that we add throughout this boot camp, those changes will automatically be updated live on your site. Next, let's look how Laravel organizes code with what's known as the MVC pattern. What is MVC? Well, right now your route in this web.php routes file, it's doing everything. It's handling the request. It's preparing data. It's returning a view. And it might not seem like it's doing that
mostly because Laravel does all that for you in this route facade that's getting this slash directory and it's returning a view and it's simple but it's doing a lot under the hood. So what does this look like as your application grows? You want a better way to organize things and that's where the MVC model comes in. So what is MVC? MVC stands for model view controller. And if we're going to take
this into an analogy, let's think of a restaurant. While MVC is not necessarily the order that everything happens in terms of model and then view and then controller within Laravel, let's talk about the controller first. This is what you would think of as the waiter in a restaurant. It takes your order, it coordinates everything, and then it brings you the food. Well, the kitchen would then be the model. This is what prepares the food. It manage the
ingredients, the your data, I guess, in an application. And then there's the presentation, how the food looks on the plate when it arrives. It's it's your view. What this looks like in Laravel terms, the controllers handle your requests. It coordinates responses while your models manage your data and your business logic. And then your views actually display the information to your users. Now, we've already seen what a view looks like. Each one has its own
job, but your controller and your model haven't necessarily been shown to you in this course just yet. So, let's go ahead and create your first controller. That way, you have a little bit more insight as to how this all fits within a Laravel application. Just for simplicity sake, why don't we move everything that we have in this routes file, route, and then return view of home. Why don't we move this logic to a controller? We're going to generate one. Now, we can do
this in our terminal for application or we can actually just do it in the terminal built into your code editor if there is one. I'm going to do that here just for simplicity's sake. We could run PHP artisan and then a command. Now, I'm going to tell you what this command is and then we're going to take a look at why this command actually exists. We're going to say PHP artisan make controller. Then we
can give a name of a controller here. But what is this PHP artisan? That is Laravel's way of running specific commands. It's Laravel's command line tool. It's your Swiss Army knife, I guess, for Laravel development. We'll use it a lot to create things. Not just controllers, but there are a ton of artisan commands that are available to
be able to run anything within Laravel. And the cool thing is you can actually create your own as well. For right now, we're just going to be using a lot in this make directory of PHP artisan commands mostly to make controllers and later we'll make models, maybe database migrations as well. Artisan commands are incredibly powerful. So, there's so much
to dive into, but for now, let's go ahead and make a controller. PHP artisan make controller. And we don't have to add anything here afterwards. If we press enter, it's automatically going to prompt for what that controller should be named. You can even see what that looks like typically in terms of casing and in terms of how it should be spelled and maybe handled within a layer of application. Because we are going to be
creating chirps, we want a chirp controller. So chirp controller. We're going to stick with an empty controller for now, but later we'll go back and look at what resource actually provides for us. And you can see it created a specific file for us. this app http controllers chirp controller. All right, let's go ahead and open up that new file
that I created. Again, that's app http controllers chirp controller. It's just a blank file, but let's go ahead add the things that we had in our web route here. How do we do that? We're going to add an index method. That's public function index. And then we're just going to return a view. We're going to return a view of home. Don't forget the semicolon. And you can see here that our
VS Code Laravel extension still takes us directly to that view that we have. So in our web routes, how do we change this to instead point to our index method in our chirp controller? Let's go ahead and clear this out. So instead of returning a view here, we're actually going to use the chirp controller. We're importing that in. It's going to be a class and then we can pass it a particular method. In this case, I'm going to be direct and pass it
that index method. Let's take a look at our browser. Refresh. Everything still works. Great. This is just a cleaner way of writing what we were doing directly in our routes file, but now all of this lives in our controller. Now, we can slowly start to add to this controller as we build out our application. Now, controllers really shine when you need to prepare data and then serve that data. Again, similar to how a waiter
might do this in a restaurant, we're going to add some sample chirps to see this in action. So, in our index method, I'm going to add a chirps array. And this is just some sample chirps with a time, an author, and then a message. Now, how do we pass this into this view? Our second parameter is going to be an array. We're going to say that this is chirps
and that chirps is going to be equal to the chirps array variable. Now, how do we display these chirps in our view? Again, if we're talking about the MVC model view controller structure, we have our controller and we're passing these chirps to our view. Now, how do we display them here? Well, this is where that blade templating comes into play. So, a home.blade.php PHP file is not
just HTML, it is blade. And we can add some templating structure to this. In this case, for every chirp, we can say hm maybe for each chirps as chirp. And then every single instance of chirps that we have in that array that is being passed in from this chirp controller, we're going to iterate over whatever
HTML that we're passing in here. So I'm just going to say end for each here to say that this is the end of that for each loop. Now we have available the chirps array. We have the chirp author, the chirp message, and the chirp time. I'm going to paste that in here again. The chirp that we're looping through the author, the message, and the time to coincide with what we're passing in to the chirp controller. Let's see
what this looks like in our browser. All right, that looks pretty good. Now you can see how our controller is going to allow us to pass additional data to different views and we can also have different methods. Let's take a look at what that looks like. What I'm going to do is I'm actually going to copy all of this and delete this chirp controller because when we used that initial method to create a controller, we just selected
empty. What happens if we then create a chirp controller that is a resource controller? This is what you might typically use in a standard MVC structure. Model view controller. This resource allows for an optional model that you might have. We don't have a chirp model just yet. So I'm not going to select anything there. Now in that chirp controller, we have seven
different methods. The index, create, store, show, edit, and update, and destroy. These are all methods that you would probably typically use within any standard MBC application. Just a hint, anytime we use an artisan command, we don't necessarily need to leave it blank. We could write chirp controller and then even pass it additional options or parameters. Most artisan commands
have this ability where I could pass it as the resource and it would automatically complete what we just had completed for us. Now you might start to see how each one of these seven different methods that we have within a resource controller can be used within our application. For example, the index it's displaying a listing of all resources. It's listing all of the chirps. This home page the create method
might be showing a form to create a new chirp. In our demo application, we're doing this on the same page. So we likely won't use this. The store where we're creating and saving a new chirp. The public function show to be able to display one single chirp. Edit displaying a form for editing a single chirp. Update would be to update that
single chirp. Then destroy deleting a chirp. We're going to be using most of if not all of these eventually throughout our application. But for now, we're just using the index method. So to recap, here's what happens when someone visits your site. This route, this slashparameter, this root of your application is then going to pass the chirp controller, specifically the index method of this
chirp controller class. The controller prepares the data. It's waiting our table to decide how are we going to present this data. And the controller passes all this information to the view. In this case, that home.blade.php PHP where that view then renders that HTML with the data and then the user sees this page. So why does all this matter? Well, right now we're using fake data, but imagine when we have thousands
of real chirps in a database. The controller that we just set up, it's going to decide which chirps to show. It's going to take our order and then decide how to present them. The model, which we're going to learn about in the next lesson, it fetches them from the database. Then the view that home.blade.php PHP at least for our index displays them nicely. So each piece has its job in the MVC structure model view controller. Your code stays
organized and then future you will will thank current you for how things are organized and displayed to your user. So in our next lesson, let's start working with real data to see how your app might remember things permanently. All right, we have these sample chirps that we're passing to our view layer. Again, this is our controller, the C of the MVC structure, and we're passing
this to our V, our view layer. But these TPS are just hard-coded values that we're passing from this controller. They don't actually exist in the database. And when you're creating an application, when you're putting it out onto the web, most of the time, you need a database in order to save things that can then live forever or at least until someone deletes their chirp. In lesson two, we talked about how we have this database.sqlite SQLite, the same one that was generated for us when we
created the initial Laravel application when that Laravel installer scaffolded it out. Database.SQLite is perfect for our local development environment because it's a real database. Everything exists in this single file. So the TLDDR is SQLite is a great option for a database. And if you did want to move it into production using a different database, you really don't have to think too much about what that change is. Laravel just handles all that for you. But let's go ahead and get
started with interacting with the database. And to do that, we need this little thing called migrations. In fact, we have a directory already enabled for us that has some migrations by default, but we're going to go ahead and create one from scratch. You can think of migrations as Laravel's way of interacting, creating, modifying, even rolling back your database changes automatically. So, it's a filebased way of saying, "Hey, here's what is
happening or has happened with your database." We're going to open up that terminal again using our handy PHP artisan command. We're going to say make migration. And again, most of the time I could just leave this blank. And if I was to press enter, it would give us the uh standard format of what a migration might be named and how you would input that into this field. So I'm just going
to say that this is create chirps table because that's what we're going to do. We're going to save chirps to our database. So we need a chirps table and this is plural just like it gave us a prompt for. Now that went ahead and created that file for us. So, if we were to open up that database directory again, we should have a new migration. Yes, this last one. And it's timestamped as well for when we created it. Create
chirps migration. Here's where we get to add the columns that we would need in our database for our chirps. You can think of this as how your database needs to be defined. What things do you generally store with a chirp entity? Now, first, most of the time, a chirp would be associated with a user. We need to know who actually proceeded to chirp. Now, Laravel gives us a handy table column for this. We can say column
foreign ID. And now here is where we can pass in the ID of another column in our database or another table in our database. For example, I'm going to say that this is the user ID. And I'm going to make this nullable. Now, this isn't recommended in a production database, but just so that we can continue moving forward with our application. We don't necessarily need a user just for testing purposes. We want to be able to create
chirps, edit them, delete them without having to worry about authentication. We'll get to that at a later lesson. And then I'm going to say that this is constrained. What this does, you can see this right here. It's creates a foreign key constraint on this column referencing the ID column of the conventionally related table. What that means is it's grabbing the user ID and then saying it's going to exist within the user model, the user table within
our database. And then this is something you might normally do within an application. I'm going to have this cascade on delete. Now, what does this mean? It means that anytime a user is deleted, their chirps are then deleted, too. All right, that's the most wordiest column in our database migration for here. So, the next ones are going to be simple. We just need a string. And in this case, this is just what it says. It is a string of characters that we can enter into our database. The first
parameter is going to be what that name is. I'm going to say this is a message. And then we can pass an optional parameter of how much this string max characters should it have. And we're going to say this is 255. And then like you might have seen, Laravel already provides the timestamps and ID columns automatically generated for this migration, which is great out of the box. We don't have to touch this. This timestamps is a created at and an
updated at column. So we might even see that in our database right here where if I was to go into something like our users, we have a created at and updated at timestamp. Back to the chirps table. Now, how do we make this migration file that we created actually then exist in our database? Well, it's simple. We open up our command line again and we type php artisan migrate. And you see here it
created that chirps table or actually it ran the migration which in turn created the chirps table. This is a schema that created the chirps table with these particular columns. Now that we have our migration entered into the database. We have that new table. There's different ways that we can interact with the database before we create any UI elements to be able to interact with the database on our web application. we can uh do interactions with the database
manually. Now, this is where the AI tooling that Laravel provides as a first-party extension, Laravel Boost, is fantastic. It has uh tools out of the box to be able to have your AI interact with your database using the tools that Laravel expects. What does that look like? Well, Laravel has Tinker, which is PHP Artisan Tinker. What this does is allow you to interact with your database using Laravel commands. And so I could
say something like uh db select and we're going to select and this is raw SQL queries. We could say something like select star from chirps. And yeah there's nothing there because we haven't added any chirps yet. But there's other ways to interact with your database. You might have seen I already pulled up this database.sqlqlite SQLite
and VS Code and other IDEs might have a database viewer extension that you can install, open up and be able to interact with the database there. And while most of these tools that are built into IDE or extensions for IDE like VS Code, they're usually just great for viewing things that are in your database and that is handy. But there's also another visual approach like table plus or
something like debaver or any other GUI editors for a database where you can point it to your database file and then be able to interact with it. For example, I could create my own chirp manually within this table plus GUI. Now, I'm discarding all those changes because we don't necessarily need to interact with the database manually for right now. Now, it's just helpful to know that either using AI or a tool or
even something like PHP, artisan, tinker, we could use these tools to create new chirps in the database before we even create code to do that. One thing I did want to point out, we create this foreign ID for a user ID table. But you might be thinking, hey, we didn't actually create that migration, right? Well, that's something that Laravel gives us out of the box. And you saw that we had that users table in our database.sqlqlite
viewer. So if we were to click into that create users migration. We're creating a users table with a string of name, a string of email that has to be unique and all of this is pretty readable for us. We have a timestamp that is email verified at which could be nullable and then a string of password. So there's a bunch of different tables that are created in this one migration. But it's helpful to know that Larbell does provide some of these tables out of the
box including users. So that's why we didn't create our own users table migration. It's just automatically using what Laravel set up. Now before we continue, I do want to note that Tinker can be used with what we call eloquent. This is Laravel's way of interacting with the database in a more clean manner. Now this isn't necessary to grasp all at once. It's just helpful to know that there are other ways of
interacting with the database other than using that DB facade in this case using uh select queries that has SQL language and that might be confusing for you but it's just helpful to know that there is a more eloquent and that's actually the name of the tool that we interact with the database within Laravel of being able to select or even create things within our database. Again, you don't have to worry too much about everything
that you're learning right now. We're going to talk about it in more depth later, but for your first Laravel application, just know that there are easier ways to do almost everything within Laravel. And before we move forward, I do want to manually create a chirp with PHP artisan tinker. Mostly to show you that there's an easier way to do it in the next lesson. An easier way to interact with our database even with the tools that Laravel gives us through
models, but that's for next lesson. But also to show you that Tinker or any way that we're interacting with our database is a great use case for something like AI. Within Laravel Boost, there's tools that allow you to work with Tinker or allow your AI assistants to work with Tinker. You don't need to know all of these syntax for how to interact with the database through Tinker, but it's helpful to know what your AI or even
what specific commands might do. I'm going to type this all out here and then later paste it into Tinker. So, we have DB table chirps. So, we're entering into the chirps table for selecting the chirps table and then inserting a message of my first chirp in the database. And because we don't have a user, we can just leave it off of this DB table. The DB is a facade that Laravel gives us to more easily interact
with the database instead of having to write those SQL queries that we wrote previously. But we do have to put created at and updated at as timestamps because Laravel doesn't give those by default. I'm going to clear this out, copy it, and then in PHP Artisan Tinker, I'm just going to paste that in and press enter. And we get this true back. So that means that this was successful. This chirp was now entered into the
database. So we could pull up our database. See this chirp and see here, yes, this message was created. My first chirp in the database. But we can also do that in Tinker as well. We could say DB table chirps get. And there we go. Here's our first chirp. Congratulations. You just entered something into the database using a command line tool. I'm
going to exit from Tinker. There's two commands I want to make you aware of within the PHP Artisan uh namespace. That's migrate fresh, which means if you absolutely made a mistake or maybe you just need to change an existing file, which is not the best way to do it, but if you're not in production, you can do whatever you want. PHP artisan migrate fresh will drop everything and then create everything from scratch. So in
this case, we don't have that chirp that we just created. Another one would be PHP artisan migrate rollback. Now if we created a new migration and in this case maybe the chirps table and we wanted to roll that back it would run the down structure. If I was to go into that chirp table migration we have this down structure and here this is going to drop the chirps table it's going to run this
migration. If we ran this migrate roll back so if I do that because we ran everything we now don't have anything in our database. So I'm going to run PHP artisan migrate again. So you now have a real database with the ability to create real things in that database in this case chirps because we gave it a table we gave it a proper structure in this case a message and then a relationship
to users and next lesson we'll dive into what does that relationship actually mean. This is where that M of MVC comes into play the model structure. So, if you've thought that this is a little bit confusing because working with uh queries and stuff like that within a database can be a little bit confusing, next lesson is going to make everything a lot easier. So, stick around. Like we explored in the last lesson, now that you have a database, there's a
number of different ways that you can interact with that database. You can use a GUI like Table Plus or DBver to interact with your database, even insert new things, delete things. uh that's a little bit more hands-on where you have a more manual approach within PHP Artisan Tinker to use maybe raw SQL which sounds a little crazy and a little strange and maybe a little scary but you can also use something like the DB
facade which Laravel gives out of the box to say hey here's a little bit easier way of working within a database but don't worry it gets even easier right now this lesson we're going to talk about models if we're going Back to our restaurant analogy, the M in MVC, model is our kitchen. It prepares the food. It organizes your data structure. It keeps everything nice and neat. And
in a Laravel application, you can use models to interact with your database in a really, really beautiful way, an eloquent way. So, as you can see here, I'm going to zoom out a little bit. We already have a model created for us. That's the user model. So, why don't we take a look at what this actually looks like? There's a few things I want to point out. First, there's things like it can use specific things within Laravel
like has factory or notifiable. We won't dive into either of those this course, but it's helpful to know that there are things that can interact with a model as a whole. Next, we have this fillable array. This is just to show Laravel that people can within your application enter a name, an email, and a password into this table in your database. And so this fillable array is the one that we're going to focus on as we create a new model for our chirps. There are other
additional arrays like hidden or cast. And what this does is allow you to uh interact with your model in even more depth. We won't touch those just yet. So let's go ahead and create our own model. Opening up our terminal again. PHP artisan make model. And then we're going to pass it a singular capitalized name for our model. In this case, chirp. Again, if we wanted to just leave that off, it gives us a little indicator of
what that should be named. In this case, flight, but I'm not using flights. I'm using chirps. So, chirp. Now, before I run this make model command for our chirp, I did want to make a note that Laravel has this time-saving flags for models that if we were to create a model, but add a dash, a parameter of mrc, this would do everything that we've already done within this course. It would create the chir model, of course. So, it would create an M, a migration,
like we did in lesson six. It would create a resource controller like we did in lesson five. That's RC for resource controller. But since we already have those, we're just going to make the model. Heading into that chirp model, just like I said, we want to first focus on that fillable array. So, in this protected fillable array, we're just going to have our message. And this is because this is the only field in our model that we need to enter into the
database. Next, Laravel's Eloquent allows us to attach these relationships between different models. That's going to be great for us because we have users that are associated to chirps and chirps that are associated to a single user. So, we can do just that. We can create a public function of user. And here's where we can type hint this to say this belongs to we're pulling that in this
use illuminate database eloquent relations type. We're going to return this which is this model belongs to and then we can pass in the user class. So in this case the user model and this is letting Laravel know throughout this application anytime we call user on our chirps we'll be able to grab the user's information that's associated to that single instance of a chirp or multiple
chirps. Now we want to do the inverse for what we already have within our Laravel application for our user. So if we go to our user model we want to have this user associated to chirps. And this is more just for simplicity sake. If I want to grab a single user's chirps then this would be helpful. We're going to do just that. Public function chirps. Again this is on the user model. We're going
to type hint this with a has many relationship and that was imported in at the top. And then we're going to return this has many. And we're going to pass in again that model of chirp class. And since we're in the same model name space, we don't have to bring in that chirp model as a import. So what do these relationships actually look like in code? I kind of talked through it
with you, but why don't we actually write it out? If I want to grab a chirps user, I could do this or this is a chirp and I want to grab the user and this would give me uh something like hey this is Josh who is the user. Again this is just handy to know how all this fits together. So in PHP artisan tinker and again well this is just muscle memory to be able to learn how tinker works and
how our model works. You could do this with something like AI or even within a graphical interface to create these new users or maybe even chirps associated with the user. But this lets us know how our models relationships also work as well. So if I want to create a new user, we could use the user namespace, the app/models/ user namespace. And we want to create a
new user. Now here's where we can input the name of Josh. We can enter the email and maybe this is joshhlaravel.com and then we could enter the password. Now Laravel gives us a easy way to enter a password without having to encrypt it ourselves. We can do this brypt function where I'm going to then enter my password and then we'll just say that
this is a testing password and then we're going to close this out. So there we go. we have our new user. So now this user can have chirps associated with it. So why don't we do that? We already have the user. So now I want to create a new chirp. So let's say a new chirp is going to be from the user in this PHP artisan tinker session. We want to say that
they're chirps. I want to create a new chirp for this user. And the message is going to be this is a new associated chirp created by Tinker. And again, close that out. Oops, I had that backwards up there. So, we need the bracket and then the parenthesis. There we go. This is a new associate chirp and it's automatically
attached to the user ID of one, the user that we just created that is then in our user variable. So, why don't we see what this actually looks like? Now, using that relationship, we can echo out the chirp user name. Oh, that's Josh. That's awesome. It's simple as that. We don't have to make a fancy SQL query in order to grab that name and then be able to make sure that that's actually our name.
It just works because we created that relationship. And of course, we can use our model in different ways, too. We can say that the app models chirp. I want to grab all of the chirps. Well, it's as simple as this. We're grabbing all of the chirps. We just have one in our database. But uh that's neat to know that within one line of code, I can get all of the chirps, all of their information, the users that are associated with them. And we can do the
same thing. Instead of all, we can say even the latest and we'll get those as well. And this is the same thing, but it would get the ones most recent first. Where if we had multiple chirps up here for all of the chirps, it would show them in chronological order, the order that they were created rather than most recent first. And all of this is going to be extremely helpful as we start building out our Chirper application
because you need all of these queries. You need these eloquent model relationships as well as knowing, okay, how do we get the latest chirps actually sent to our view? I'm going to exit out of Tinker. Now, let's go ahead and update our controller with our real data now. Because if we remember in our chirp controller, we were just passing in fake chirp data. Well, instead, instead of this chirps array, why don't we actually
grab the chirps from the model? We can say chirp. We can bring in that model right up here. Use app models chirp. And I want to say I want to grab all the chirps with the user. This is so that we can eager load that user relationship and it prevents N plus1 queries. In that case, having to query the database multiple times for things that we already have. We want to grab those chirps via the latest. Let's say we want
to take 50 of them. Maybe this is so that we don't uh have all of the chirps loaded on one screen. There's other ways around this, but for now, this is going to be the easiest. And then we're going to get those chirps. And we shouldn't have to change anything else because we're still passing that chirps variable to our chirps home. So, there's a few things that we need to change in order to update our view to accept this real data. First of all, it's not an array anymore. It's an actual model. And
that's going to look a little bit different. I'm going to paste this in. Then we'll walk through exactly what changed. First, I changed things to for else. This is a little bit easier, but mostly so I can teach you something new. For for else, this says for else all the chirps as chirp. This still exists in the same way, but if it's empty, then we can show an empty state. There's no chirps yet. Be the first to chirp. And then everything that we would have
passed as an array in our PHP now is the chirp message. This is associated to that model. Now, chirp created at and this is a cool little Laravel helper diff for humans which is going to tell us how long ago did this actually happen that specific date. And then this is just showing that it's going to say the username if that user exists otherwise it will be anonymous because again we
have the ability at least right now to say that no user has to create a chirp. We can create one without having an authenticated user. So what does this look like in the browser? Well, looks like this. You can see this was a chirp that was created by us. We did that within Tinker. I'm going to go in the database and create some more just so you can see in our chirps. We're going to create a new one. We don't have to use it as a user ID, but I'm just going to say this is
my second chirp. And we're going to say that this is the same date and time just for simplicity sake. There we go. We have an anonymous chirp because this chirp does not have a user associated with it. Let me do this a couple more times. And there we go. We're starting to see how this is turning into a realworld application. We're having things stored in the database. At least we're being able to then read them and also take relationships from them saying, "Hey, this is anonymous. There's
no user associated with it, but this one has a user and that user has a name." just to confirm how those relationships work. Instead of showing user name, maybe I want to show user email here. And there we go. There's the email that I entered for my user that I created. So now your app has real data. You have chirps that are in the database, but you now have an easier way to work with those chirps using models and specifically using Eloquent within Laravel to query that data, but also
write that data as well. And those relationships between users and chirps is something that's going to make this application a whole lot easier in the end and every application that you make within Laravel. So next up, let's clean up our application a little bit. Get some UI nicities in there, componentize some things, and then get our database and our application ready for users to start entering their own information. All right, our application is starting to take shape, but it looks pretty
basic. This is the start of having our full chirper application, but let's do a little bit of transformation, a little bit of TLC. We're going to add some user avatars, format some timestamps, and then utilize Daisy UI's uh components to make this look just a little bit nicer. The first thing is this home.blade.php is great, but it'd be nice if we could get every chirp as its own component. So that way we can only have one place that
we're modifying just the chirps that are being shown. So in this case, this whole card right here. Again, we can create components within the components directory. I'm going to create a new file that says chirp.blade.php. So let me go ahead and paste in this chirp component and we'll talk through some of the things that we changed. So here's pretty close to what we had previously, but now we're just making it a little bit cleaner. Now, if there is a
trip user, we're going to use this avatars.l.cloud, which is a free service to have these neat little gradients for you whenever you're needing these avatars that we're having for our application. We're just passing in the user email to generate them specifically for that user. And then we have a default one for anonymous users. Now, here's the neat thing with blade components. We can pass in a prop. In this case, an array of chirps, or in this case, a chirp model, a chirp
instance of an eloquent model. And this prop then allows us to access the chirp user or chirp user name or things like a chirp created at or chirp message when we use this component in our view. And that's what we're going to do in our home view. So in our home view, we're going to uh we can clear this out, but I might just replace everything. And let me paste this in. And so here we still have an empty state. We changed that up a little bit to make the styles look a
little nicer. but we are passing in a new component that Xchirp component that we just created. We're passing in the prop. And in this case, that's what a colon indicates. It's a prop that we can pass into the component of the chirp. So, we're still looping through all the chirps like we used to before. We're just looping through it in the instance of a component. Let's see what this looks like in our homepage. Great. I cleared out some components and so we just have anonymous components for it right now. But this is looking pretty
good. So now that we're cruising along, why don't we get some more sample data without having to open PHP artisan tinker every time we want to do that. Laravel gives us an easy way to do this with something called cedars. If we search for cedar in our application, we have this database cedar file. And you can see here we have a user factory already created, which this just means that a new user can be created if we run
a cedar within our database. Cedars are a great way to make sample data that we can then just make sure our application is looking and feeling and working the way we would expect. We can create a cedar, you guessed it, with the PHP artisan command. So I'm going to say PHP artisan make cedar and we're going to call this chirp cedar. We won't get into factories in this particular course, but factories are a great way to make random
data where within cedars it's going to be a little bit more specific. This is basically just telling our database, let's run a particular command. Let's do some things within models or eloquent as we're populating the database. You can think of Cedars as an automated way to run PHP artisan tinker commands. So you don't have to type it all out. I'm going to paste this in here. And so these are just some sample chirps, an array of chirps. We're just saying if there are
less than three users, which currently there are in the database, let's go ahead and create some new users with this information. Again, this is exactly what we would do within Tinker. This is just making it a little bit easier for us if we wanted to uh ever create multiple versions of this data. For each chirps as message, every user is going to get a random chirps based off of this chirps array. And so running the cedar
command is as simple as saying PHP artisan dbced. We're going to pass in the class of the chirp cedar. And that database was successfully seated. Again, a cedar is just an easier way to have all those tinker commands run for us, but with in a way that Laravel expects. So in this case, we're just running all that PHP code, but seeding the database with it. Again, we're not getting into factories, which is the actual creation
of randomized data that you might have seen in that user factory file, but that's for a different course. So, if we were to take a look, oops, this looks good, but it looks like we have a CSS issue with a little bit extra spacing now that we seated that database. Yeah, I think it's because we have these P tags which are adding some extra uh block classing that we don't need. I'm just going to replace them with span classes and a gap of one. There we go. That's what we want. So now we have a
reusable blade component for chirps. We have a way to generate chirps if we ever needed to uh kill this database and start it up again. And then we have a clean way of showing user information as well as generating a specific avatar for that user based on that user's email. So we're moving right along. Next up, since it's still read only, we're going to let users create their own chirps. So let's
actually make this social network thing social. Our chirper application is showing chirps that we have stored in the database. But we still don't have a way for our users to actually create their own chirps and then store them in the database. So that's what we're going to do in today's lesson. We're going to build a form. We're going to handle the validation with that form and then we're going to store those chirps that users create in the database and all of it
happens with the things that are built into Laravel. Now, we're still saving the actual user authentication for a later lesson, but we are going to allow our users as anonymous users to create those chirps. So, why don't we add the form at the top of our feed and we can get going from there. We really just want a form right about here after the latest chirps header and then before we actually list the chirp. So, I'm going to put a form there, but we're not going to wire this up. Nothing is actually
going to happen when we submit this form. It's just a plain HTML form. There's nothing special about this with one text area and then a button to submit. But yeah, there's nothing that actually happens when we hit submit. If I was to type anything here and hit submit with this chirp button, yes, the message comes up in a URL parameter up here, but we're not actually doing anything with that information on
Laravel's side. So, why don't we hook this up? First, I actually want to create the method that we're going to be submitting this form to in our controller. So, why don't we go to our chirp controller? And this store method is going to be the perfect method to do this because this is creating a resource, in this case, a chirp. And this is what is intended for this resource controller. We already received the request information. So, we're just going to validate that. This is
validating the request. And then we're storing in this validated parameter. We're saying hey this message that we're receiving from this request is required should be a string and a max of 255 characters. So now we have two places where this max is indicated in our validation as well as in the database itself. Of course we can also add this to the front end as well. I believe we might actually be doing that. Yes, max
length of 255. So this is great to have the front-end validation as well as the backend validation. This is Laravel's way of validating anything that comes in through a request. We have specific validation parameters that we can add. Most of them you'll find in the docs are pretty self-explanatory. And believe me, there is a ton of them. Next, we're going to create the chirp. So, in this case, we can use the chirp model to say, hey, we're going to create
this with a message of the validated message and the user ID of null. Of course, we can actually omit this, but we're going to add this back in when we get to lesson 11 and we add authentication. And lastly, we're going to return a redirect. In this case, we're redirecting back to the homepage with a specific success message. In this case, we're going to say that there is a
success that the chirp has been created. This is an easy way for our application to know that hey this was successful in Laravel. This with function is returning with a flash of data to the session. So in this case after we redirect back that initial redirect that initial load after this has happened flashes a piece of
data to the session and that data is this success message that has the value of chirp created. We'll see in a little bit how we can grab this information if a chirp has actually successfully been created and display that to our user. For now, let's hook this up in our web route. So, similar to our route get, we're going to have a route post and we'll say this is the chirps route and
we're going to pass in the chirp controller, the store method. All right. Now, in our home.blade.php PHP where we have this form. How do we tell this form to submit this information to the slashchirps post route that we just set up? Well, it's actually really simple. For this form, we're going to say that there is a method of post because we are posting to that /chirps route and the action is
going to be to that specific route, the slash chirps. Now, there's one more thing that we need to do within Laravel. It's this at CSRF directive. What that CSRF directive is doing is the equivalent to a hidden input field attaching a CSRF token like you might see here. This is something Laravel automatically generates and gives to you out of the box. It's incredibly easy to use, but it's given to you so you can
easily protect your site and your application from cross site request forgery, CSRF. And that should be it. Why don't we test this out and see if our form works the way we expect it to? It's one of our latest chirps. This is a test of our new form. Hi there, Boot Camp Chirp. And look at that. Because we are redirected, we automatically receive that new chirp
because the slash route is automatically getting all of the latest chirps and pushing them into our view. Now, here's one thing I want to make you aware of that we're not going to touch in this course, but something that you might want to look into in the future. It's keeping this form up to date. Right now, you can see here that when we post it, it was 0 seconds ago. I haven't touched it, but if anyone else accesses this
page, it will see it in a different timestamp because it's when they requested that data. If I press refresh, okay, now it's 1 minute ago. So, I'm not going to see any new chirps until I actually refresh the page. Well, Laravel has some great options such as websockets within something like Laravel Reverb in order to say, I want to watch if there are any chirps that are coming in or if there has been a new chirp that
comes in, I want to maybe notify all users that a new chirp has come in. Again, not something that we're going to be touching on in this course, but it's helpful to know that those options are out there and it might be a great way to kind of build on top of what we are building here with Chirper. All right, we have this form and it works. We're submitting anonymous data. We don't have to worry about the validation error because if I tried to chirp, uh, it says, "Please fill out this field."
Well, we have client side validation, but we also have server side validation as well. Why don't we remove the client side validation so that we see what our server sends back? I'm going to remove this required parameter. And just for fun, I'm going to remove the max length as well. Now, when we submit our form, we would expect maybe some error, right? Because we don't have the client side validation and we do have the server
validation in our chirp controller. We have validated that this message is required before we even continue with the request. And if we hit submit, well, we're refreshing the page, but nothing's happening. Now, the neat part is that Laravel gives if there is any errors within the session that has been passed to the view, it has an errors
prop. In this case, this is a specific variable that we then have access to on our view. So just for some quick debugging we can add this if there are any errors why don't we dd the all of those errors dd is a little quick helper function that Laravel has that is specifically saying we're going to die and dump in this case shut down
everything that Laravel is doing at that time and just show this when we take a look. So if I click chirp, look it, we have an array. That's our errors array and it includes a single error. The message field is required. So how can we make this better for our users? Well, let's go ahead and do this. Instead of just having this text area, we're going to add a few things. We're going to say that if there is an error with a message
parameter, that's what we're passing from the controller. Well, then let's go ahead and show that message. And this error message is also coming from the text area with the name of message. Daisy UI also gives us the ability to have the text area of an error and so that just displays it easily within the CSS as well. We also have this old message. So when we flash a status
session, we're redirecting to the page. Then this message text area is going to display the old variables. So, if we for some reason went over 255 characters, we should then redirect and see the old message in the text area with the error. For now, just to show this off, we're going to say a max of 255, but a min of
five. Now, if I try to enter anything under five, let's say, hi chirp, the message field must be at least five characters. That's an error message that Laravel automatically created for us based on our validation errors. We returned, we had a full redirect. We see the hi message still in this text area, but now we are able to fix this. Hi
there. Chirp. Perfect. I'm pasting way more than 255 characters in. We should get that same error. Perfect. Let's go ahead and reset everything. And in our home, we're going to add back in that client side validation.
If I try to add any more characters, you might hear me hitting my finger on the keyboard. I can't because that max length is affecting this text area field. Great. But what about the success message as well? You might have remembered in our app.css, we added this animate fade out parameter. This is so when we do create a component that is a notification component for any success
messages. This is going to make things a lot easier. And actually, we're not going to put this success message in our home.blade.php. Instead, we're going to put this in the layout. So, I'm going to go to our layout.blade.php. And just under the nav, why don't I put this? In this case, if the session has a parameter of success, why don't we show a toast? The toast is going to be the toast of top. And this is all mostly
Daisy UI, but we also do have that animate fade out class that we inputed into our app.css. This is saying that we're just going to take that session value, the success message, regardless of if this is from a posted chirp or if we use this in logging in and registering. Let's post a new chirp. And there we have the neat little notification up there at the top that
nicely fades out. Now, to add just a little bit of UI nicity before we get into the next lesson, if we tried to create a new chirp and we have an error message, of course, we get the client side validation. But if for some reason uh we create something that is over 255 characters or we bypass client side validation somehow we're just going to get the generic error message that we saw initially. What if we wanted to
customize that? In this case if I remove that required client side validation go back into our form and click chirp we get the message field is required. It feels a little I don't know not chirpery. So to show off the power of Laravel, we can actually customize these validation messages. We can say uh the message required text should say please write something a chirp or the message max text that then gets sent back if
this validation does not pass. Chirps must be 255 characters or less. Why don't we even change up this success message as well? Your chirp has been posted. So refreshing chirp, please write something to chirp. Now all of a sudden within a couple of seconds because of what Laravel gives to us, we have the ability to modify something as simple as error messages that we don't have to do hardly anything. Now in the
next lesson, we'll start working on editing and deleting chirps even before we get to the user authentication piece. But it is helpful to know that while we won't touch on it in this particular course, there's so much more that you could add here, even for this particular lesson. What if you don't want your users to post five times within a second or maybe a 100 times within a second? There are some bad eggs out there and really you can't trust anyone on the
web. Well, Laravel has the ability to rate limit. What that means is that you can within a matter of minutes say, "Hey, this particular chirp method can only be done by a user maybe one time every 60 seconds." But before we get into something like that, why don't we check out how you can edit and delete chirps. See you in the next lesson. No one's perfect and everyone makes
mistakes, typos, you name it. Uh, so if you don't want to just start the day with a nice cup of Kofi, maybe we should add the ability for our users to edit their chirps. And the neat part is this completes the whole CRUD operations within a MVC structure in a Laravel application. So CRUD, create, read, update, and delete. So let's do the update and delete parts. All right. In
our chirp.blade.php, php. That's our component for the chirp that we are looping through anytime we have new chirps. Why don't we add the edit and delete buttons first as well as the form to do it. We just won't hook it up just yet. So this probably go great after yeah probably after this timestamp. I'm just going to add this in. Now this is a edit button. We're passing in the chirp
ID. Now this is helpful to know. We want to target a particular a singular chirp and this is a way to do that within blade. What this looks like is we are saying hey we want to go to the slashchirps route but we need to pass in a chirp ID and then we're going to edit it. We'll hook up how this works within our web route in just a little bit. Next we do
have another form. Again, we do have to pass in that at CSRF method, but this is going to be a method of delete. So, we do have a method of post with a method of delete. And that is necessary because HTML forms do not have a standard method of delete. So, Laravel gives us this handy directive similar to this route that we're showing up here to go to the edit form. for our delete button. We
have the action of slashchirps and again passing in a chirp ID. All right, this might seem a little bit complicated, but bear with me here. Most of everything that we're going to be taking a look at when it comes to editing and when it comes to deleting means that we have to do it within a single instance of a chirp. And that's why we have this whole chirp ID uh inputed into these routes because we need to find which chirp we
need to edit and we need to find which chirp we need to delete. So why don't we in our web routes we can just continue to add those route colon parameter. So we can do a route get and we can do this for slashchirps slash and then we're going to add in a specific chirp ID and that happens within these curly brackets saying that hey we need a particular instance of a chirp and then I'm going to say this is
the edits and just for now I'm just going to add the route put and we're going to do the exact same thing of chirps slashchirp again in curly brackets and then the last One is going to be route delete and that's going to be slashchirps slash and then chirp in curly brackets. Now we're going to add the actual controller methods to this so that they actually
function the way we want. But this curly bracket chirp is the exactly the same thing that we are doing here. This chirp within the curly brackets is what we would call route model binding. We know that we need to get an instance of a chirp. And so this just gives Laravel an easy way of saying, hey, within this, we need to look for something that resembles or we can identify as a chirp. Now, we're just going to pass in those
chirp controller classes. So, we're going to say a chirp controller, and this will be the class with one of uh let's go ahead and say this is the edit one. And just for simplicity sake, I'm just going to do the rest. So, update and destroy. Now, Laravel does have a shortorthhand so that you don't have to do all of this. And we're doing things a little bit differently just because we
have a git in the root directory and not a git of slashchirps for example where we're listing all the chirps. We're doing that all on one page. But what we could do is something like this. We have a route resource where we are resourcing because we have that resource controller and passing that resource to chirp controller
class. And then we could say uh we need to pass in everything but only really the store, edit, update, and destroy. And this is identical to these four right here. or just an easier way of putting it. For right now, I'm just going to be extremely explicit. Now, let's go ahead and create the edit view
that we will need because we are getting a new route /s/chirp. This is that route model binding and edit. Why don't we create that in our file views and then in view since we don't actually have a directory for chirps because our chirp index is technically the index of our whole application. I'm going to create one chirps and then in that chirps directory we're going to have ededit.blade.php.
Let's create a directory. Then we have edit.blade.php. I'm going to paste everything in that we have again on the laravel.com learn page. You can find that for this lesson down below. This is the same layout that we are using throughout our application. We pass in a new slot title with edit chirp. And the majority of this form is exactly the same as our home.blade.php just with uh different buttons and a
different form. And this form we are using the put method for that action chirps ID. Well, where does this go to in our web route? We have the put chirps chirp. This is the update method. So that way instead of creating a new chirp, we're really just updating one. And now this text area needs to have the chirp that we need to edit, right? So, we are passing in the old message, the chirp message, so that when we are
directed to this edit page, we see from the get-go the actual chirp message that exists within this chirp instance. We're going to be passing that chirp into the view within our controller here in a little bit. And then we have a cancel button that's just directing us home. Why don't we hook this up to our chirp controller. This would be in the public function edit method, which is showing the form for editing the specified resource. Again in a resource controller
for a standard MVC Larville application this is just best practice. So we might say here we're going to return a view and in that view we're going to say that this is the chirps.edit page and this dot is going to say that this is in the directory of chirps. Again in our uh views directory we have the chirps directory. We're going to use the edit page within there. Now we do
want to pass in the chirp right because in our web route we are getting this chirp route model binding. In this case we need the instance of the chirp in our edit.blade.php because we need the chirp ID to be able to post back to whatever chirp we're actually editing. And then we also need the old message. What is the message of the current chirp that we're editing? And here in chirp controller, instead of
the string of ID, well, we could use this to kind of find the existing chirp based off of maybe an ID. Maybe that ID helps us find that chirp. But we can use route model binding. That's exactly what I kind of talked about here in this web routes. We have this chirp parameter. And because we know that this is the chirp model associated with it, we can automatically assume what chirp this is
based off of that ID because when we go into our chirp.blade.php, that's that chirp component and we wanted to edit a chirp, we are passing in the chirp ID. So this is Laravel's way of saying instead of having to search the database for a particular chirp with an ID, Laravel is just going to do all this for us. And it's going to look like this. We're going to pass in the chirp model with a chirp variable. And then we can use this compact method.
This is saying, hey, I want to pass everything from this chirp into this view. And there we go. So what we're doing here is saying when this edit method has a chirp associated with it, a chirp model, let's just pass everything that is associated to that chirp into the view. Again, create an array containing the variables and their values. Oops. It looks like this button is a little bit out of whack when it comes to our styles. But if we click edit, you can see maybe here in the lower left side of the screen that it's
/chirp/7. Clicking on it, we get this view /chirps/7. That's the seventh chirp. And it automatically knows what information to bring in. I'm going to cancel. Let's fix this. Just for simplicity sake, I'm going to add a new div around these two divs. So that way we can separate them from the actual message. And then we can have this div be a class of flex with
just five between a width of full. And then we do need this to take up the full space. So flex of one. Again, just a small change. And yeah, that looks a lot better. So now that we have this new edit page, let's go ahead and link up this uh update chirp button as well as the delete button. And this is going to be done in our chirp controller. So first the update method. Again we want to pass in the chirp model. So we're
going to use the chirp model and it's going to be a chirp. This is going to be similar to our store where we need to validate something first and then update the chirp. So we're just going to copy and paste this and then change it. Instead of creating the chirp, what we're going to need to do is grab the chirp and update it with the validated info. And then instead of redirecting with a success of your chirp has been
posted, we can say uh your chirp has been updated. Let's try this out. Now I can finally fix this typo. Update chirp. Your chirp has been updated. And look at that. Now you might notice a few things and we'll get to them in the next couple of lessons. Like we can edit anyone's chirp. Well, that's not necessarily good and we'll fix that when authentication comes into play in the next couple of lessons. First, let's go ahead and make
this delete button work right now. As you can tell, nothing happened. One thing that's really cool to note that if you just copy and paste it in, I wanted you to know that this is there in the delete button. If we click on it, it pops up with a browser modal. Are you sure you want to delete this chirp? And of course, this isn't hooked up just yet, but this exists on the on click method within a button. We want to
return a confirm. This is just an HTML modal, an HTML confirmation modal. Are you sure you want to delete this chirp? Just something neat. All right. In the chirp controller, we need to add this destroy method. Again, you guessed it. We need the actual chirp first. And then we're just going to say that we can delete the chirp. Why don't we return a redirect with the same kind of message saying that this chirp has now been deleted.
trying this out. Delete. Okay, your chirp has been deleted. But again, it's not very good if we can delete anyone's chirp. We'll get to authorization in a little bit and what that means. But I do want to give a sneak peek on what this will look like when we do implement authorization and authentication. In this case, when a user is logged in, how do we know that they are able to edit
and delete their own chirps? Let's start off by using an authorization check that Laravel gives. It's something called a policy. And you guessed it, we can use a PHP artisan command to make a policy. Now, we already have a chirp model that this policy should be modeled after. And if we leave that blank, we can say that this is going to be the chirp policy. And we need to apply this to the chirp
model. And there we go. If we now look at this chirp policy, this gives us an idea of what can actually happen within a chirp. This is just a clean way to put all the code that we might need to check if a user is able to do x, y, or z. And then in our chirp controller we can do something as simple as saying this
authorize delete and passing in the chirp. What this will do is it will say um has this authorize method of delete for this particular chirp does this user have the ability and in our chirp policy uh in the delete it's returning false but I could say this is returning true instead and of course we don't have a user just yet but what this chirp
controller is now going to check is does this user have the delete authorization to be able to delete this particular chirp I just wanted to give a sneak peek on what this would look like as soon as we have users able to be creating chirps, deleting them, editing them. It's as simple as this authorize. But then in our chirp policy, making sure that this is correct. Instead of returning false or true, we really need
to just check is the user the chirp user. And because we have model relationships, it makes it easy. We can say chirp user is user. This is saying if the chirp user is the user that is trying to make this request then returning true. If it's not, we're returning false. And we need the same for here as well. Again, we can't put this in the trip controller just yet.
So, we're going to remove this authorization piece. But once we do set up authentication, then we can add that back in for the destroy method as well as the update method. Lastly, before we move on from this lesson, I do want to change how something is updated or shown when something is updated, rather. So, if I edit this and I say, wow, and I update this, well, we don't know that this was actually edited. We don't know what the original was. We don't
necessarily need to worry about that, but it'd be nice to know that this was updated. and not just sent 2 hours ago. I mean, most social media platforms have this problem at some point in time, so we might as well get ahead of it. In our chirp component, in addition to the diff for humans, we really just want to add this if statement. If the chirp has been updated at, and if that updated at is different than when the chirp created at
at least by 5 seconds, then why don't we show this little edited text? And there we go. This was posted two hours ago, but it was edited. If I edit this one by our anonymous user, new post edited. Things are really coming along. Why don't in the next lesson, we add authentication. At least the first piece of it. We're going to allow our users to register to create new accounts. And you'll see how easy this can be even without a starter kit.
We're finally going to make use of the sign in and sign up button. First in this lesson, the sign in. So, we've been pretending that we can uh edit or delete any chirp that is added. And right now, anytime we add a new one, it's just an anonymous person creating this chirp. Laravel offers complete authentication scaffolding with Laravel's starter kits. But it's also helpful to know how to manually build it first to understand
how things work under the hood. So, let's start off by creating a new page. So, we have our chirps directory where we have our edit page. So it makes sense to do a new directory that is an oth page. So why don't we do o and then we'll have a register.blade.php. Let me paste in this code for us. Now the majority of things that we're seeing here are not new. We've seen them throughout our time together. We have a slot where we're saying this is the
register page. We're using a layout. We're using a bunch of different forms. We're gathering any errors that we might have. We're showing those error messages. And then we're using old inputs if we have any errors. So again, not much new, but let's see what this looks like. Let's go ahead and attach it to our web routes just to keep things simple for now. Let's go ahead and say route view. And this is the
slashregister page. But this is our o.register view. Now let's go ahead and make sure in our layout we are actually directing to the /register page. And we are not. So let's do that. slashregister. Oops. Slashregister in the signup. So, sign up slashregister. This is creating a new account. Great. Everything looks good. So, we have a name, we have an email,
and a password and a confirmation of a password. Just while I'm here, why don't I make this the /lo route. Now, we do need to register a user when they complete this form. We could create a new maybe authentication controller, but what we're going to do is kind of split this up into different controllers. We're going to use PHP artisan make controller. And here's where we're going to go against the grain just a little
bit. Instead of saying that this is a O controller or a register controller, even I'm going to say that this is the O/register controller. And this should be a invocable controller. What this looks like is a single controller created in the O space. So /http O and then register controller. And what
this looks like is a single class, an invocable controller, which just means that usually you only have one method per controller instead of having a resource controller that has multiple, in this case, seven different methods. So really something like this versus something like this is personal preference, but I did want to show two different ways that you might do it. So that way everything that we're doing
within O, we're going to have invocable controllers instead of one massive uh authentication controller that has weirder method names because we don't necessarily have an update method when it comes to authentication. We don't necessarily have a show method or an edit method. So this is just a different way of doing this but we just pretend that this invoke is whatever method we normally would use in our chirp
controller for example but this is just our register o controller and when we call it it's going to use this invocable function so almost identical to any other method or form that we've done I'm pasting this in we need to pull in the user model and we're going to pull in the hash support facade as well as the O facade. Here's what's happening. We're going to validate the
input. We're going to get the name, the email, the password. We're making sure it's confirmed, and that's what that password confirmation field that we have is. We're going to create the user with a hash of that particular password. And then we're going to log in the user, redirecting to the home with a status of success. Welcome to Chirper. And that's it. It looks like this shouldn't be as easy as it is, right? But it is mostly
because of the helper methods that Laravel provides. Not just the authentication helper method to be able to log in the user that we just created, but also things like a hash to make passwords secure. And because we already have a user model that's given to us out of the box within Laravel, even if we don't have a starter kit that we started with, this just becomes incredibly easy to get a register controller or any sort of authentication up and running. Why
don't we add this to our web route? So in addition to our view, we're going to add a post route. Route post of register. And we're going to pass in that register class. You can see here that it's grabbing that O register controller. Now, there's something I want to add right now. Why don't we say that this is the register routes so that way we know and it's easy to see them at a glance. But I do want to say that
these routes should be able to be accessed by anyone even if they're not logged in. This is where middleware comes into play and Laravel has middlewares built out of the box for us. In this case, for the register route, I want to make sure that this is accessible by guest. So, we're going to say this is a middleware of guest. And you can see here that we have that middleware available to us. And just for fun, I want to show us what a named
route looks like. In this case, we can pass in a name. And I'm going to call this the register route. And we can do the same thing with our post method as well. We're going to say that this is a middleware of guest. And we don't necessarily need to name this because we're just posting to the slashregister route using the register invocable class that we just created. This name helps us say, hey, instead of knowing that it is
the /register page, maybe we change this to slash uh I don't know, new for some reason. Well, then we automatically know that it's still under the named route of register. We can actually update the navigation instead of this href to register to use a named route. For example, instead of that href of register, I can pass it this route. And in here, we might be able to see yes, the register named route. And again, the
VS Code extension is doing a lot of heavy lifting right here. Now, I do want to update this as well because when we're logged in, we shouldn't show the sign in and sign up page. Well, that's where the at@ off parameter or the AT off directive I should say comes in. So instead of this sign in and sign up, we can say okay well if there is O in this case if someone has authenticated into the application then we're going to show
the O user's name and a log out button. We'll set this up in a little bit. Otherwise let's show the buttons like we had them previously. What does this look like? We have the sign up button that still works even with our named route. Let's go ahead and sign up. Josh register. Welcome to Chirper. You can see here that we have my name. Logout's not going to work because we haven't created that route just yet. So, just so we aren't stuck with this particular user that's
logged in. Why don't we create that logout route? We're going to create a new controller. PHP artisan make controller. This is the O/ logout controller. We'll say it's invocable. Now in this logout invocable controller, it's going to be the inverse of what we did for register. We're going to grab the user with the request user. Then with the O facade, we're just going to say, hey,
let's log out that particular user. We're passing in that user variable. And then we can return a redirect with another success message. You successfully logged out. Let's add this to our web routes. So route post of log out. And again, that's what we're doing in our layout where we are creating a form, a method of post to the action of log out and the CSRF. And that's exactly
what that button is going to do. When we hit that logout button, we are going to call this route post of logout and that logout class that invocable controller that we just created. I'm using the middleware of Oth and this is to show that yes there are multiple middlewares that Laravel gives out of the box and O is one of them. So in this log out option right here what we're doing is saying okay only someone who is
authenticated can actually hit this log out button. Of course we have that in our layout here with O as well. So now hitting log out and yeah you successfully logged out. Now I can't sign back in because we haven't yet implemented that. But let's go ahead and protect the rest of our routes and update our controllers to use our user. Now we can actually group routes with middleware. What we can do here is route
middleware. We can say this is the O middleware. We're going to group everything in this with a function. And we're going to say that, hey, um, within this whole route middleware group, I want to grab everything and put this in there. Now, uh, everything that we see here is now under the middleware off. So, I can't send a new chirp now unless I am authenticated. So, what does this
look like? Well, if I try to send a chirp, hi there. And I hit chirp, what do you think is going to happen? Well, Laravel gives you something out of the box that because it knows you're not authenticated, it's going to try to authenticate you. And yeah, we don't have a login route to find, which is the default redirection that Laravel gives when you do not have an authenticated user and you try to hit a specific uh route that uses the O
middleware. That's okay. We know it's working. Let's go ahead and update our chirper controller because here now we're not just creating a new chirp. We are actually creating a new chirp with our user. So why don't we do that within this store method. We're going to use the O helper and we can say that the user of this O helper we want to get their chirps but we want to create them and so we can actually create them with that validated parameter. Now my editor
is going to give me an error that this method of user is not defined but rest assured this is correct. And then since we set up that policy in order to authorize a user to update a particular chirp, we can add that here. Now this authorize if they are authorized to update the chirp, then let's continue. And same thing with the edit form as well. And then same thing for the destroy method as well. And since we are
authorizing a particular user in this update method, well, we don't have to say uh we want the off users chirp to update because we already know that they're able to update this particular chirp. Same thing with being able to edit or view that edit page in general. Now, we still see these edit and delete buttons. I'm not logged in, but we've started to authorize if someone is able to do this, if someone's able to edit or delete. Now, if I tried to do this,
because we have that middleware, I should get an error. Yes, the route login is not defined. But how can we only show these edit and delete buttons when we are able to edit and delete this in the chirp.blade.php component for these edit and delete buttons. Let's go ahead and change this. We're going to say if the O check exists, in this case, if they are authenticated, and if the O ID is equal
to chirp user ID. And actually there's an easier way to do this as well with a blade directive. Instead of this if O check and O ID is equal to the chirp user ID. Okay, that's great. But really we just need to check that policy that we created. Can they update or can they delete a chirp? And if they can update it, they can delete it. So we can just
use this blade directive of can. Can can they update the chirp? In this case, the chirp that we're passing in. And then the can directive. Oops. The end can directive. There we go. In this case, we cannot edit any of these. Uh, and I cannot delete any of them because I'm not logged in. But I'm going to sign up, create a new account, and show you after I create a chirp that I can actually
edit and delete them. Sign up. Josh 2. Looks like we have error messages out of the box. Good. Register. Perfect. my first chirp chirp. And look it, we have our user avatar associated with us because we have logged in and I can see the edit and delete methods. I can edit and uh-oh, looks like we have an issue here.
Ah, yes, our controller probably has not used the authorization or being able to use the authorization trait. I don't believe I set that up. So let's go to the chirp controller and if we want to use the this authorize what we can do is make sure this controller is set up to authorize use authorizes requests that pulls in the use illuminate foundation o access authorizes requests trait for
this particular controller. Perfect. And now that we made that change now our controller is using that authorizes requests trait. We have the ability to have those authorization policies available. So, we can edit the chirps that we create. Edit my first chirp. Edited and update chirp. Perfect. And we can delete it. Your chirp has been deleted. Fantastic. Hopefully, this shows you that authentication doesn't have to be too scary. Authentication
within Laravel is actually incredibly easy because of the tools that it provides. And while yes, it's great. You can just grab a starter kit from Laravel and you have authentication out of the box. you don't necessarily need to do it every single time. That being said, starter kits are great because they have a lot that we're not going to even touch within Chirper, such as password reset pages. But last but not least, why don't we get the ability for users to log in?
Because if I log out, I can't sign back in just yet. So, let's do that in the next lesson. I've created at least two accounts now, mostly because I don't have a signin page just yet. So, let's fix that. We're almost done. Let's keep going. Let's make it so we don't see this 404 not found error again. At least on this login page. In our resources views, we have the O directory for register. I'm
going to create a new file for login.blade.php. And we can of course start with the register page itself and just make changes like that. Or you can just copy what is in the lesson on larville.com/learn and paste that in. And yeah, there's nothing too crazy here. It's exactly what the register page is, just with fewer forms and directing to a specific method of login. You can start to tell
how a lot of this is repeatable in the sense of once you get the hang of what a form looks like, especially if it's a form that has similar fields, the next time you implement that form, it's going to be a lot easier. And Laravel just makes it easy, too. We created an O logout class already. We just need our o login and we can do that all in one command make controller and we're going to call this o/lo
and we're going to pass the invocable method. So if we go to our login o controller yes this is our invocable single class controller. This is going to be one of the few controllers that's a little bit different but only slightly. We're going to pull in that off facade. So what this off facade is doing is we're using the attempt helper with this facade. We're taking the credentials that we've been given, this
email and password. We are attaching the remember checkbox if they gave that and we're requesting a new session. We're regenerating that new session. You can see here this attempt helper automatically has that remember variable. If it's false, it's false by default. Otherwise, if we pass that in, then it's true. This is doing all the heavy lifting for us. and then we'll return back.
Otherwise, if the O attempt fails for whatever reason, then we're going to return back. This is a neat little return helper to say, "Hey, we're returning to the previous page regardless of where that was because maybe the user tried to chirp and we're going to go to the homepage, but maybe they tried to log in. So, we need to return back to that login page." But for the most part, uh, we are just returning them back to the login page because we
do have those errors. Now, you might see how this could be as simple as this or it could get a little bit more complicated if we wanted it to. We could have additional validation methods to say, okay, maybe we need to make sure that they have, I don't know, they are logging in in the proper place. They uh are not trying to log in multiple times. And you can do all that with Laravel and there's a lot of great helpers
available, but this is just the absolute basics. We're logging them back in again using the O facade to attempt to log them back in with the credentials that they've given. When you do need to step into a little bit more trickier applications, when you want to log someone in, but want to make sure they're only logged in once, of course, Laravel has those helpers available to you. But that is also where some starter kits can be incredibly helpful to be
able to have that kind of out of the box or at least have the starting base, the foundation out of the box ready to go so that you can add on to it with the helpful Larbell documentation. And seeing that we're requesting the session to be regenerated, it did remind me that I think we want to invalidate the session as well in the logout controller. So instead of just logging out this user and we can actually
simplify this with o logout because we already know the authenticated user then we can say we need the request session and we're going to invalidate that as well as the request session let's go ahead and regenerate a new token so that way the user who is then not logged in still has a fresh token. Let's go ahead and add this login route to our web
login parameter route host of login and we're going to use that login class. We're going to use the middleware of O and name this the log in. Why don't we name the log out as well?
Even though I don't think we're using it anywhere, but it's also helpful just in case we wanted to use it. Again, similar to how we used it in the layout for this register route, we could go ahead and do this for the action of logout if we wanted to. Oops, I accidentally put the get instead of the logout method. And I see what I did. I don't necessarily want this to be a named route because we are
using the named route for log out. What I do need is the route view to be able to pass in the login page to the login class. This login blade view I should say. And this is where we can have the middleware of guest. And we do want this removed from here as well. Or at least the middleware of guest for this particular login route. And this is what we can name the login route. And there
we go. That looks a lot better. So now we have this login page. If I was to log in to my previous email that I created, we are welcomed back. And this log out button should work even with the named route. And there we go. And while I haven't done a good job of showing you how often you should commit and push to your GitHub repository, the neat thing is because we set this all up within Laravel Cloud where as soon as you push
any changes, it's automatically going to be deployed. Uh we can do that as often or as little as we might want. Although it's better to do it as often as you can. But let's go ahead and do that right now. So we can add everything that we've done. We can commit this as the let's do it and we'll go ahead and push this. And so what we'll see now is the opportunity to then view our full
application live ready to go and with everything that we've built but now hosted on Laravel cloud. So if we go back to cloud.laravel.com and sign in with your account that you created, our chirper application has now been deployed. We can click on this and yes, we have our application live now on Laravel Cloud in production ready for all to see. And it looks like it's waking up from hibernation right now.
And yeah, we could be the first to chirp here. So why don't we go ahead and do that? We'll sign up. We'll say first Laravel application created. Go and chirp that. Fantastic. It looks great. And hopefully yours looks just as good, too. Just to recap, if we try to create a chirp, because we have this middleware attached to any of the post methods for creating a chirp, editing a chirp, or anything
like that, of course, we can't see editing or deleting a chirp. I cannot click on this. It takes me directly to the login page. Of course, we can register a new account if we would like, or I can log back in. We're using the default authentication, the O helper and facade that Laravel gives, which includes remembering us and remembering that session. We have the
ability to add new chirps. We can see that this chirp is attached to our particular user. If I was to add another one, it still uses my user and my little avatar. Logging out and signing in with a different email means that I cannot edit or delete these chirps that another user created. But this is my chirp and I can definitely edit this
full CRUD functionality of being able to create, read, update, and then delete all within a neat little chirper application. Now, this is looking pretty good for someone like myself who is not a designer. But thankfully, I have some incredibly talented designers on the Laravel team and with the power of modern CSS like Tailwind CSS, which comes out of the box with Laravel's starter kits, you don't have to worry
about that. But with that little bit of CSS, we can go from something like this to this. So, let's take a couple minutes and I'll just show you what I did. You can find everything to copy and paste in the article section of the laravel.com learn page for this video. We're just going to add a whole bunch of stuff to the app.css. What that's going to do is a lot of stuff that you probably wouldn't normally do within modern Tailwind, but
just for simplicity, I don't want you to have to modify too many files. It uses some custom theming to take everything that we already did and just make it look a lot nicer. And that's the power of Laravel where it is just HTML and CSS just with some added nicities. And with Tailwind being something that comes out of the box within starter kits, you can just do things like this. Now, in the layout file, I'm going to add some OG
images and some fab icons. Here's the code for them. And then with those new fab icons added in the public directory, we're going to add a new image directory as well. images and then here's where we can put our OG image. So then in the layout, all these fab icon assets as well as the OG image are Laravel VS Code extensions showing us that yes, these are accurate. And then instead of this chirper button
with this cute little emoji, well, we've got a nicely designed logo now. So I'm pasting that in. Now in the layout, because we have that custom theme, I'm just going to say that this is the Laravel Chirper theme. So this is using that Daisy UI custom theme that we just created in app.css. and the chirp.blade.php, I'm going to remove the shadow. Same thing with the edit.blade.php from that card. And then back in layout, we're going to add this new footer
instead. And then also in the chirp component to keep it on theme with the colors that we have with this new logo, I'm adding this uh vibe is ocean to this avatars.cloud name just to keep it on theme. And then just small changes to the login and register to have this be text with an empty margin top of one.
Go ahead and commit these changes. And we see this new git push being merged in Laravel cloud. So we should see this live in just a few seconds. And look at that. It looks like it was successfully deployed. So we can access this domain. This is where we pushed this up to Laravel cloud and we have our brand new freshly designed Laravel
chirper ready to go. So congratulations. Give yourself a round of applause. You built your first Laravel application from start to finish. So in the next lesson we'll take a brief look at what's next. Congratulations. You've just built your first Laravel web application from start to finish in about an hour, depending on how fast you're able to follow along. We started from nothing and we were able to get a multi-user authentication,
authorization, everything, a social platform deployed with the power of Laravel. It takes all that complex stuff that you might be scared or hesitant on in your development journey and it makes it simple. You've been able to take this chirper application, put it on the internet. It has user authentication. It has a full database that you can and write to and also view. It also has security features like CSRF forms that
Laravel gives out of the box as well as password hashing. There's tailwind CSS that we use with Daisy UI. And then all of this is neatly wrapped up within everything that Laravel gives from start to finish from nothing to deployed. And so whether this was your first Laravel application or your second, third, fourth, fifth, whatever that might be, the great thing is it's always going to get better. Not only can your Chirper application have room to grow, there's
fantastic things to learn and maybe your Chirper application is a great uh starting point to say maybe uh user profiles or the ability to search pageionation, maybe even uh upload and display user profile pictures. What if you wanted to have uh people be able to like or favorite individual chirps? Or you could go more advanced with like real-time updates with Laravel reverb or
notification system. Maybe you use AI with Laravel's Q system and so you kind of put it through this system of is this able to be uh chirped. Maybe you want to get into that level of censorship. I don't know. The great thing is you've only just scratched the surface and Laraveville has so much to offer, not just in its ecosystem, but with the whole community as well. So, as Taylor
Otwell said, we must ship. So, hopefully this isn't your last application. I'll see you next time.