Test Driven Laravel - Building a customisable sidebar menu | Arturo Rojas | Skillshare

Playback Speed


  • 0.5x
  • 1x (Normal)
  • 1.25x
  • 1.5x
  • 2x

Test Driven Laravel - Building a customisable sidebar menu

teacher avatar Arturo Rojas

Watch this class and thousands more

Get unlimited access to every class
Taught by industry leaders & working professionals
Topics include illustration, design, photography, and more

Watch this class and thousands more

Get unlimited access to every class
Taught by industry leaders & working professionals
Topics include illustration, design, photography, and more

Lessons in This Class

17 Lessons (2h 30m)
    • 1. Introduction

      1:41
    • 2. Homestead

      12:25
    • 3. Were to start

      1:48
    • 4. New Project

      2:59
    • 5. Our First Test

      6:46
    • 6. All Green

      21:02
    • 7. Refactoring

      19:11
    • 8. Creating Users

      10:20
    • 9. User Validation

      10:44
    • 10. Updating & Deleting Users

      21:51
    • 11. Installing Admin LTE

      2:43
    • 12. Login View

      2:01
    • 13. Dashboard View

      2:14
    • 14. User List UI

      5:39
    • 15. Create User UI

      14:19
    • 16. Update User UI

      11:58
    • 17. Delete User UI

      2:01
  • --
  • Beginner level
  • Intermediate level
  • Advanced level
  • All levels

Community Generated

The level is determined by a majority opinion of students who have reviewed this class. The teacher's recommendation is shown until at least 5 student responses are collected.

49

Students

--

Projects

About This Class

Learn how to apply Test Driven Development in Laravel 5.4 while creating a small but useful project.

Create an administration panel with a customisable sidebar. Create, update and delete menu items and assign them to users to see the sidebar update immediately.

By the end of this course, you will acquire advance techniques on:

  • Laravel 5.4

  • Test Driven Development

  • Acceptance and Unit testing

  • SQLite in-memory database for tests

Meet Your Teacher

Teacher Profile Image

Arturo Rojas

Teacher

Class Ratings

Expectations Met?
    Exceeded!
  • 0%
  • Yes
  • 0%
  • Somewhat
  • 0%
  • Not really
  • 0%
Reviews Archive

In October 2018, we updated our review system to improve the way we collect feedback. Below are the reviews written before that update.

Why Join Skillshare?

Take award-winning Skillshare Original Classes

Each class has short lessons, hands-on projects

Your membership supports Skillshare teachers

Learn From Anywhere

Take classes on the go with the Skillshare app. Stream or download to watch on the plane, the subway, or wherever you learn best.

Transcripts

1. Introduction: in mother and A applications. Writing tests has become an increasingly important skill. That's give you the confidence to say that your application work as intended, eliminating the probability off box, going into production and causing problems to your users. The problem is that more often than not, you are going to be working on a deadline, which means that you are going to focus on finishing your product first. By the time you're done, there is probably little to no time to go back in star riding tests for your application. And even if you do have the time, this can be a very difficult task. So you end up probably not doing it. By using test driven development, you are going to first write the test a failing test, and that will drive your development while you try to make that failing test pass. Once you make your failing tests passed, then you go back to your coat and optimize it. Do any re factoring if necessary, and then you move on to the next test and then you repeat this cycle until you have a full product. By the time you're done, you will have a full application in all the tests to back it up, giving you the confidence to say that your application work the way you want to in the next few hours we're going to apply. It is driven development in Lauraville to create a real life application. With this, you will acquire the necessary knowledge to create unit and acceptance tests for nearly every aspect of your application. So whenever you are ready, go ahead and click on the next lecture where we are going to start setting up our development environment using level homestead. 2. Homestead: So the first thing we're going to do it set up our development environment. We're going to use lateral homes as I mentioned before, so go ahead it in this it level dot com and go to the documentation. Make sure you are in the $5.4 version of the documentation because that's the version that we're going to use from here on. And look for the section that says Getting started in Click on Homestead and scroll down a little bit into We don't need to know about the introduction, and we know that it's ah, what homesteaded with if you don't know what homes that is basically a virtual machine that comes with all of this stuff. We're right here. It comes with a bun to 16.4, comes with gate pH. Being in genetics, my SQL etcetera, etcetera. So it's got it's got everything we need. So scroll down to the installation and set up steps, and the first step, as described here, is ah, you're going to need to install a couple of software packages 1st 1st 1 is virtual box. Here is this 5.1, but I'm at the time of this recording. Actually, the latest version for veritable boxes five point wind out 22. So if you follow the link from the documentation you will be taken to here and here. All you have to do is click on the operating system that you have minus always six operating systems who already went ahead and download this package and is telling it is a very simple process. All you have to do is go ahead and double click the package in my cases at the empty file. And from here you just double click under view 12 bucks installation package, and then all you have to do is basically continue and follow up the instructions on the screen already installed mine, So I'm not gonna do it again. The next package that you have to install its cold bag syringe again. Just follow the link from the documentation. You will be taken to the download page of background up dot com and from here, just select the operating system that you have again minus Mac OS. It's 10 in. The installation process is very similar to veritable box. All you have to do is click on the installation package within the DMG file in my case, and again follow the instructions on screen to install itself where, since I already have mine installed, I don't have to do it and a second time, So just go ahead and close it. Once you're done installing the software, the next step will be to install the actual homestead Bagram Bucks. And to do that, all you have to do is run this command on your terminal. Let's go ahead and do that right away. Just paste it here and hit. Enter now from this menu you have to select, which is the provided a beautiful machine provider that you're going to use. And in our case, we already downloaded and installed beautiful books. So we're going to select option number two and hit Enter. And here it says that I already have them the box installed and downloaded, so I don't have to do it again. In your case, if this is a fresh installation, is going to download the box and he started on your machine. But eso that you can see the process, the complete process. I'm just going to go ahead and use the force flag so that it will add it again and ignore the previously installed one again. If this is a fresh installation, you don't have to use force black. You just have to type in it as it is, and it will down in the box one more time. Let's select the virtual machine provider, which is beautiful box. As you can see, it's going to take some time to download. So I'm just gonna pause a video here and come back when the process has done. All right, The process has finally finished. You should see this message of the end successfully adding a box lateral homestead version 2.1 point zero. That is the version of the time of this recording. If you do not see this message, try to update your your Bagram version to the latest one. The next step in the process is to actually install Homestead. So we do this by cloning this repository in our machine. It is recommended that you do it on your home directories that that's what we're going to do. We go back to terminal cleared screen. I'm already on my home directory, but you can access it quickly by type in CD and this static turnover here. And then I'm just going to copy and paste this command here to clone the repository and hit . Enter. And this will create a new folder, Cold homestead. So I'm gonna city into its city. Holmes it. The next step will be to check out the latest stable version off Homestead because sometimes the master branch is not stable. To do this, simply click on this link, which will take you to the release page. I'm gonna go back here, which will take it to this page at the time of this recording. The latest stable version of Host Homestead is version 5.3 point two. So that's the one that we're going to check out using this command from here to just check out version five Boring 3.2. I think they're quite that. Yeah, that's the one hit Enter in there. You have gonna clear the screen. Next. We have to run this command on Mac and Linux X. You have to run thes bash. Be neat. That s H. It'll be the comment around. If you are windows, you just have to execute this dot Bad file. This command will create the homestead configuration file. So let's go ahead and execute this command. Just copy and paste. Just remember that you have to be within the homestead folder to run this command. And you should get this message Homestead initialized this check that the file is created. There you have it. Homestead. What a ML or yeah, mo, as I call it. And with this, we're done styling. Host it and we have to move on now to the configuration step. Go back to the documentation. First thing will be to check the configuration file in the provider sections. I would Let's go back to a terminal and open this file. I'm going to use V I and in the provider section expectancy since we made the selection previously, when we were download in the box, we have the provider said to beautiful box. The other thing that you want to configure is your folders. This will be the shared folder that you're here to machine will share with the operating system. And this means that when you create this folder here in your operating system, it will map it to a home bag, grinned code folder within your virtual machine. I'm not gonna worry about the NFS configuration steps or any of this either. So let's move on to the configuration of the engine. Next sites. If you take a look at the configuration file, we already have one side called homestead dot a ppd. This will be the site, and you will use in your browser to access your application. And it is mapped to home fag grand code larible public. Since the file is already pretty well configured as it is, I'm not going to do any changes. So I'm just gonna close it out and I'm gonna make sure that I have that code folder with in my home directory. So I'm going to go back to my home directory real quick, and I think I already have a code folder in it. That's right. Now to create a lot of a folder that is configured already in our homestead configuration file. All you have to do is type in composer, create project, not a bill ladder pill. Call it a lot of ill. This will be the folder name for a project and finally specify the version, which is 5.4 and then hit enter already went ahead and created one. So I have this folder created within my code folder, so I don't have to do it again. As you can see, I already have folder created, which means that I already have the configuration and all the folders mapped correctly. Let's move on to the next step off the configuration, which has to do with the hosts file in Macro X and Lennox. This file is located on their E t C hosts and you have to open this file and at this line inside so that when you type in the homestead that up in your browser, it knows that it has to associate this address with the i P 1 92.1 68 10 the 10 which is the configure i p address for your virtual machine. If you go back to the homestead configuration file, look at the files time use, Um d I You can see that the I P address has already been configured for you at the top of the fire with the homestead configurations. Already. The last step will be to lunch the Bagram box, and you can do this by simply typing vagrant up from within your homestead directory. So let's go to a Terminal one type in vagrant. This process will take a minute or two, so I'm gonna post the video and come back when it's done all right. The process is complete now. It's worth noting that you shouldn't be alarmed when you see this warning here where it says connection recent retrying because it's just trying to connect to the background box while it's booting. So don't pay attention to it. It will eventually succeed. And you will see this message of the end, meaning that your box is up and running to make sure it just go to the browser. Open a new browser tab in typing homestead dot a PP and there you have it. We have a literal application running within homes. It's the last thing I want to show you is how to access home step using the termina within your homestead folder. Just typing vagrant. Yes, it's age, and with this we are connected the ssh! Into the virtual machine. If you check the contents of your home folder, you can see that we already have a code folder and within it we have the level folder that we map to it. Now we have a completely isolated development environment where we can develop our application. In the next lecture, we're going to create a brand new project for our admin panel, and then we're going to start thinking about what we are going to test. First, we will delineate the features of our application and decide which is the best one to start with. 3. Were to start: Let's start by delineating what will be the features of our applications, we will have a logging and log out feature where a user can look and logging and log out of system. Once a user has been locked in, he will be taken to a dashboard page and in that desperate dash for page, there will be a sidebar with menu items in it, and the user can see the menu items that has Bean assigned to it. We will also have administrative features where we can create, update and delete menu items. And also we can create, update and delete users and also assigned many white student. So here we have to make a decision. What we test first, where do we start testing to the side will just think about what is the most important feature of your application. Logging and log out can be implemented later, and maybe you want to have the system open to everyone from the start and then adding authentication later, and that can be done and administration features well. Maybe you can have someone to create many items and users directly in the database. In that way, people can just go into a dashboard and see the many writings that they have assigned to. So that tells me that the most important feature and the one we can start testing with is just the dashboard page and being able to see the menu right inside. A user has a scientific. With this in mind, we will go ahead and create scaffold or bar application created, banging lad of a project and configure it within the homestead configuration file, setting up the new site for it. Once we have that running, we can start delineating or sketching our first test. 4. New Project: to create our new application. I'm going to logging to the Bagram box using vagrant. Yes, it's age and I'm going to navigate into the code folder here. I will create a brand new lateral application using composer. I would call this new Project Admin panel. I know you specify the version fighting for and he entered. Brooks made a mistake. It's not. Backslash is actually forward slash my bad. Hit it again with the new project. Created this. Jump into the ethnic panel product shoulder and use composer install to download and install all the dependencies. Looks like there is nothing else to be in start or updated, so the next step will be to add a new site to their home state configuration file. I'm going to exit vagrant and we'll use V I again to update the homestead the Yamma found. I'm going to modify this sites section to add a new site. So I below this line on going to add a dash map. Colon admin panel got a PP and I'm going to map it to home vagrant code admin panel, public. Save the file. Finally, I'm going to edit the E T. C hosts file to add in the new side definition. As you can see, I just have to add the I p address 192.168 Got 10 Dunton and map it to admin panel dot a pp . Save the file. Whenever you make changes to the homestead that BMO found on the side section as stated in the documentation, you have to run this command to re provision the virtual machine and configure the new site . So let's do that right away. We're gonna copy this, make sure you are within the homestead folder and now the virtual machine has bean re provisioned and the new site has been configured to make sure everything is working. Okay, I'll open up a new browser step and navigate to admin panel, got a PP and now we can move on to writing our first test. 5. Our First Test: in every different installation of Lauraville. There is already a full destructor for all of your tests, and they all go inside this tests folder. Within this test folder we have a feature folder which will hold all over acceptance tests . And the unit folder will hold Oliver unit tests. They both come with an example Test for us to begin now, as I mentioned before for the first is that we're going to write. We want to test that a logged in user can visit the dash for view and he should be able to view all of the menu items that he has assigned to him. Open up a new terminal window. I'm going to go into my home state poll there first, and from here, I'm going to launch my vagrant box using pigment. Oh, the reason I'm doing this first is because I want to do all my development in all of the terminal commands that I want to run. I want to do them within the virtual machine. One of the virtual machine has started. Just access it via ssh using vagrant ssh! And from here, less access. Our application folder is City code Azmin fennel. Now, to create a new test class, simply type pH B. Artisan make test. We're going to call this class dash for test. Remember that you have to use the test word at the end of the class so that BHP Unit can identify the class as a test. Now that the test has been created successfully. Let's go back to our editor. And as you can see, we already have a new class called That's four test opened that one up. Now I'm going to delete most of this. I don't need this public function. I'm going to write a new one. All of the test that we are going to write will follow the same structure. First, we will have an arranged section here. We will set up anything that we need in order for the test to run properly. Next, we will do the action part where we will actually perform the test that we want. And finally we will have the Assertion Park where we will make all of the surgeons to make sure that the results of the test where the ones that we expected so to begin this, create a new public function and here you can do two things. You can either prefix the name of your function with the work test, or you can simply at a annotation at the beginning of the function called test so that BHP Unit knows that this is actually a test case. I will call my test can view items assigned to user. So first we do the arrange for here. We have to think what we need. In order to perform the test, we will need a new user in the system. And also we will need a couple of many writings and also assigned those many items to the user. To do this, I'm going to use a technique called direct model access where I will set up everything I need in the database directly and then perform the test to create the new users in the database. I'm going to use lateral model factories to do that. I simply type you, sir equals factory. And I'm gonna have a motorcycle yusor class and then called the create method. I will use the same technique for the menu items. So menu items factory, many item quest, create and finally to attach those menu items to the user. I would do something like this. You, sir. Many white things, a touch. And actually, I just have one menu items. Well, let's change the name of that variable to be more descriptive. And then we call attach many whiting I d. And that is pretty much everything I need for the arrange. For as you can see, that are some things here that have not been created yet. And that is okay, because when you have a failing test that says will tell you what to add to your code so that you can get that test to pass, So then we move on to the action part here. I want to visit the dashboard and get the response back in. Asserted in that response. Somewhere in that page, the user name and the menu item assigned to that user is visible, so I will get the response that is equal to this get. And this will be an http get method here. I just passed the U A rail that that I want to visit, which will be that's work. And then in the Assertion Park, I will use that response to make all the assertions that I need to make sure that I can see what I want. For example, I want to know that the user name is visible somewhere in the page. So I will use response a search, see user name. And also I want to make sure that the menu item is visible as well. So response 1/3 scene menu item Next again. From here, you can identify that some of the elements that I have just used are not being created or do or do not exist yet in that it's OK because when we have a failing tests again, that failing test is going to drive our development. So with this, I can just go ahead and run the test for the first time. She'll go back to your terminal and from within your project folder, simply run the HB unit. And this is actually good because we have our first failing tests. It says three, because little has a couple of examples test. So I'm going to go back and delete those right away. Never back to the terminal run the test one more time using PHP unit, and that is more clean. We only have one test, and from the ever description, we can identify that we are trying to use the user class. But we have an important yet now that we have our first faintest, we're going to start developing in adding Coto our project in order to get the test to pass , and that's what we're going to do in the next lecture. 6. All Green: to fix the first error. We have to simply import this class into the test file. So go back to the editor and I'm going to import the user class like so Now go back to the terminal in test again. Now we're getting an ever saying that the table homestead dot users doesn't exist. This means that level is trying to connect to the default home state database and looking for the table users that doesn't exist yet. Figure back to our editor and open up the database configuration file located in conflict. Got a ways you can see that little bill is trying to connect to the default Devi connection specified in this environment variable or going for my SQL as a default. And if you scroll down, you can see the definition of the my A secure connection. Now for testing purposes, I don't want to have a real database created. Instead, I'm going to use an SQL light in memory database now to set the values for this Devi database and Devi connection environment variables. I will use the PHP unit that XML file. If you open that one up, you can see that down here it's already setting up some of the environment variables like the app em, with a value of testing cash in session Driver both said toe array and the Q driver is said to sink so at a new one with the name DB Connection and give it a value off. Yes, secure light. I will add one more with the name D B that is in the value off column memory cool. This will create an in memory database. Every time I run my test, and when those are finished, the database will disappear. Now let's go back to our terminal and test one more time. Hopefully, we will get a different ever. Now it is complaining about not signing the table users. We know that he's trying to use the in memory databases because we have no schemer. Now we need to create the stable users in our in memory therapies. To do that, we're going to use migrations if you go back to our editor and open up the database folder and also the immigrations. Further level already come screen start with default migration for the table users, and the migration will create a table called users with an i d. Name an email with a unique and strength the password. A remember token column in a couple of times time codes in order to run this migration every time the test runs but we have to do is go back to our test class. And at this trait at the beginning, database migrations like this use that I raise my gracious, that will make sure to run the migrations every time we run the tests. So let's go back to our terminal and this one more thing. Now we get a never saying that we're unable to locate factory with name default in tests feature many white, and this is because the man United Glass doesn't exist yet. Sure, this creating new model class using PHP artists and make model. Call it many right. Go ahead and test again, and it's still complaining about it. And this is because we haven't imported this menu item quest. So go back to your editor in this important menu. Item class can see the use statement up here, go back to your terminal and test again. Now is complaining about not able to find a factory for the admin United class, So let's go ahead and define a new model factory. We can do this inside Database Factories folder in the model factory that PHP file. As you can see, we have the definition for the use of modern factory. Now we need a new one for the menu item, so we just have to sit factory. I could find at many white class and then a closure function that receives a faker generate . Call this faker. We're going to generate a random word using faker word, and then I'm going to return on array. Disarray will have a text column with the war that we just generated and also a link color with a forward slash and work. Let's go back to your terminal in test one more time. Now we have a different ever saying that we don't have a table called menu items. This means that we have to generate a new migration for to do this from simply type THB to send make immigration, it's called it create menu items stable. It's heavy. Create fleck with menu. I think this this will add some code to the migration to help us create the meaning light and stable and save some time with the migration created, Go ahead and test one more time. Now he's saying that table, many writings has no column name text, so we have to go into the migration and at that girl, open your editor and navigate to database migrations. As you can see, we have one new migration called create menu items stable and inside it. We already had some code of trying to create in many light and stable, and he went ahead and created an I. D in a couple of times steps. Now we need a new column for the text. This will be a string kal. Let's go ahead and says one more time. This new ever says that the table Many items has no column named Link, so go ahead and add that color. This will be also a string color. Just one more time. No, we're getting and never seen cold, too. Undefined Method Eliminate database query builder menu items. Now there's this may be a little confusing because we're trying to use this menu. Items on the model, not the builder, but lateral will defer any missing methods from the model into the base builder. So what we have to do is go ahead and create this many lightens method into the model. But here, I'm going to use something called an inside loop where I will go ahead and create a unit test for this method. Specifically, have that test fail, then make it past in circle back to the acceptance test. So let's go ahead and create a new test using PHP Artisan. Make a fist that's called this user test. And to have this Tess created in the Unit folder just at the unit flag at the end, let's go back to the editor and opened a new test that you can find the Tests unit folder. I'm going to remove this and just at the test annotation and renamed The Function can attach menu items for the arrange part. I'm going to create a new menu item using the model factor, and I will also create a new user using the same method. Now in the action part, I will simply attach that menu item to the user. You, sir, menu items, the touch, and I will pass the menu item Mikey. Then on the assertion, I will simply say this. A Cirque equals one. You, sir. Many writings can't I want this many whitens method to be a many to many relationship between the user and the many writers, and I want to use the attachments. Third, from the belongs to many relationship to attach new menu items to the user. So let's go back and test one time, and we're back to the ever where we can't find the many white stable. This is because we're not using the database Migration Street to list. Use that and test again. Now we haven't ever in the can attach menu items test. It looks like we imported the wrong class, So let's go ahead and fix that. We wanted to use the APP. Use it test one more time. Now we have a different error, saying that the menu items matter does not exist began. Don't be confused by this being part of the builder class, because a lot of it is just deferring the missing method from the model to the builders class. To fix this, go back to the editor and open of the model located in APP folder. And let's add that myth test again. Now he's complaining because we're trying to call the attach method on No, this is because we're not returning any values from the many white kids. And like I mentioned before, I want this to return. A belongs to many relationship. So let's turn. This belongs to many, and we pass in the related model, which is up many white test again. Now we're getting another Ever seen that we cannot find a table called menu item User. This is because many to many relationships need a people table toe work. Inaudible is that swim in the name of the table based on the model names. So let's create a new migration for that table. This in PHP Artisan Make migration School it create menu item. Use it table again list at the create at the end with the name of the table test again, we haven't you ever seen that menu item use? It has no column name menu item i. D. This will be a reference to the menu item I D in the menu items stable, So let's go ahead and add that column. Tour Migration opened a database migrations folder and let's open the create menu item user table this new Coehlo into your type. When this call it menu item, I d go ahead and test one more time. We have a different ever saying that the menu item user table has no column name. You said I D. Journalists at this new come to the table, which is a reference to the user ready in the use of Stable has had a new integer colors called User I D. In test again. Now we have a different error, saying that if we scroll way up way, way up, it's saying that it's failing to assert that this whole page has the text haven reaching. And this is great because this is telling me that the unit has his passing and now he's trying to assert that this name is in the dashboard page now to have any figure out what the problem can be, I'm going to add a new assertion to the test. Besides making sure that I can see the user name and the manual text, I will both show make sure that I'm getting a good response back, so I will use response asserts Statues 200. Let's test again. Okay, It looks like we are receiving a 404 status instead of a 200. A 44 status is basically not found, and this is because we're trying to visit a dashboard route that does not exist yet. So let's go ahead and create a drought, and we will do so in the routes web dot PHP file. And I would remove all of this and just creating your out. Now, instead of just adding a function to get away with test, I am actually going to add the code that I wish have and that is having a controller for the dashboard. So I will say dashboard controller in that controllers should have a index method bestest one more time. Now, instead of ah, 404 code were receiving a 500 coat. This is actually an error in the server. To get an indication of what he ever can be, I'm going to go back to the editor in open D Storage looks folder in check on the ever look from the error log, I can see that he's complaining because the dashboard controller class does not exist. So let's go back and create the controller using PHP Artisan make controller Dashboard controlled in tests again, we're still receiving a 500 ever so going back to the locks. Now he's complaining because the method index does not exist. So let's go back to the controller class, located in APP, a city P controllers dashboard controller. And that's creating new method called index. This test again. Great. Now we're getting a different error. He's failing to assert that empty string contains the name Western Good will. This is because we are not returning a view from the controller myth. So let's go back to the editor in turn a view called Dashboard Index. So go back and test again and we're back to the 500 code. Let's check the locks. Now he's saying that the View dash for index was not found, so let's go ahead and create that view, and we will do so in Resource is views. We will create a new folder called Dash Work, and inside it we will create a new PHP file called Index That Blade that BHP Let's this one more time and we're back to this saint error again. He's failing to assert that empty string contains the name, and this is because the view that we just created is empty. To fix this problem, I'm going to start adding some HTML content to my view. So let's go back to the editor and in the index stub later, peach being I'm going to add a PETA breath and just simply this play you, sir name. Now before I go back and test again, I want to get rid of the law because it's starting to get a little too big that way I can identify new ever so easily. Now go back in test. No, we're receiving an error. So let's go and check the locks Now it's complaining about this undefined, bearable. I had a type of the variable name that we go and correct that First. And to fix this error off an undefined variable, we have to pass down the user viable to the view. So let's go back to the controller. And here we will get the currently logged in user and then pass it down to the view. There's going test again, still getting errors going. Check the locks. Now he's failing with the ever trying to get property of non object in the view. Actually, I am trying to get the currently logged in user, but if you go back to the test, I'm accessing the dashboard without actually being logged in. So this will return No to fix this. I'm going to modify test and right before the get method, I'm going to use acting us and I will pass. They use it, and this will use the user information this variable and pretend that that user is actually loved in the system. So let's try and test that now we're back to the failed assertion. But this is different because he's trying to assert that the full content off the view contains the world. E T. These e t is actually part of the many white in text to fix this. Let's go back to the view and display the contents of the menu item viable. The way want to display this is basically have the many writings Biyani on order, at least so I will create it. You will, and inside it I'm going to creative for each loop and IDA rate over the use of many enlightens as a menu item and for each menu item and going to display and l e with the text of the menu It this test again. And now we have all over test passing and we have a green steps. In the next lecture, we're going to go back to the code that we just created and do a little bit of re factory. For example, I want my cyber to be on a separate do in northern bedded on the dash with you. Also, I want to create a view composer for the sidebar that will pass down the use of information automatically. 7. Refactoring: in this lecture. I want to take a moment to just do us a little bit of re factoring on my application and set things up like a real lateral project. For example, in my index, the index of my dashboard. I don't want this the cyber to be part of that view, but I want that to be some of you. So what? I'm going to do its on the Views folder. I'm going to create a new folder called Section. And inside that folder I'm going to create a new PHP file called Cyber That Blade that BHP in here I'm going to create and a side deck. And within that site, Tech. I'm going to create a new section that, and within this section tack, I'm going to just bring this content from the index to the sidebar. That way, the sidebar will be on its own view, and I can included on layout menu that I'm going to create now. So again, on the views folder within Resource is I'm going to create a new folder called Layouts. And then I'm going to create a new PHP file called Admin. That blade that BHP this layer will be the general layer that I'm going to use to create every single view. From now on, I'm just going to create a basic HTML file, starting with the dock type HTML and then an HTML section for the whole page. Then it had and body inside the body. I'm going to include the Seidler section dot cyber and right below the cyber. I'm going to create a new section with yield content, so the general layout will always include the cyber. And then every single view that I create only has to implement this content section here and extend from the admin layer. Sure, let's go back to the index of the dashboard can create an extends section, and we will extend the layout admin and then create a new section. Cool content. Close it out with end section. And within this section, I'm just going to display maybe an age one with the title dashboard. No, let's go back. And just just to make sure that nothing has broken, looks like nothing has broken because we are still green. The last improvement that I want to do to my coat. It's in the controller. I don't want to be passing the use it every time I creative you. Instead, I will like that user to be passed down to the cyber every time the cyber is included in the general layer. To do this, I'm going to use a view composer if we check the documentation for view composers in level , we see that first we have to create a composer service provider class, which extends from the service provider based class. And we just have to implement the boot method where we combined a composer to a view using the view composer method. And we can do it in two ways. We can either bind it toe an actual class, the composer class, or we combined it to a simple closure. Since we are doing test driven development, I'd like the 1st 1 better because I can write a unit test for this new class. And not only that, I can write another unit test for the composer service provider class itself. Let's start creating a unit test for the composer service provider from your terminal. Simply type pH being. Ericsson may test composer service provider Fist, and we will add the unit flag at the end. Now let's go back to the editor and open the new test. I would remove this comment again just and the test annotation, and I'm going to rename this can boot side but view composers. Now let's go back to the commendation just to see what we have to do. We have to call the View composer method and past two arguments, which is the name off the view in the class. This tells me that I'm going to have to mark this view class, which is an implementation of the View facade and said the expectation off the call to the composer method. With this to exact arguments, we will begin with the arrange section where we will save you and I'm going to import the view for said in That ever comes with a handy marking method called Should Receive and he re passing the name of the method, which is composer. We're setting the expectation that this should be called ones with arguments section side, but which is the name of the view and then the name of the class. That should be up. Http. Composer's sidebar. Compose it. We already know that this class doesn't exist, but we're going to let the sailing test. Let us know that next we need to create an instance off the composer service provider. We do this by creating a new variable called composer service provider and called new composer service provider. From the documentation, we know that this composer service provider will extend from the service provider based class, which is an implementation off Illuminates Support Service provider. If we examine the implementation of that class, the constructor takes one argument called APP, which is an instance of illuminate foundation application. Locally, we can have access to the application class using this AP, and this is because in the implementation of the test case based class, we're making use of the straight called Creates Application. If we examine that we see the level is creating an APP variable by requiring the bootstrap a PP that beach being. But let's go back to work this case. So we're passing this application to the constructor of the composer service provider class , and finally witches have to call the composer service provider boot myth. No, we're not having an assertion section this case because the expectations that were defining in the most part are basically on a range section in a certain section of the same time. Now let's go back in test again. It is complaining about the composer service provider class not found, so we have to go ahead and create a class, and we're going to create this new class inside the up providers folder. So now we have the class composer service provider, and I'm going to extend right away from set of the spotlight. Let's go back and Chest is complaining again about the composer service provider not found , and this is because we have no imported this class. So let's go back to the test and import of the class. My editor does it automatically, but you can see that you statement over here. Let's go back and test again. Now it's saying that the good method has not been defined within the composer service provider class. Let's go ahead and at that method to the class and this again. Now it is saying that the Method composer with these two arguments should have been called exactly one time but was called Cyril Times. We can fix that by going into the implementation of the boot method and you're saying View , come closer and we pass in the view name, which is section side, but and then the class name that should be at a state Keeping composers sidebar. Composer This this again We're back to the error off the acceptance test called Can View items assigned to use it, and I can see from here that we find an interesting problem. As you can see, he's trying to assert. Got the HTML contains the name Bryan Connell somewhere in the page. But as you can see from here, it's turning the quotation mark into this code. I'm going to fix this real quick by going into the cam view items assigned to user. And instead of just trying to assert seeing the user name, I'm going to add HTML entities and rep the user name around in at Aflac cold E N T. Quote to make sure that any quotation mark from the user name will be transformed into an HTML coat and that will fix that problem. So let's close this and go and test again. And as you can see, we're back to green. But if you check the implementation of the compulsion service provider. Passing a string of a non existent class will not give us any error. So instead, I'm going to choose to use cyber composer class. This should return the name of the class in string, but will give me a never saying that the class doesn't exist yet, which is what I want. So go back and test now we haven't ever, which is good. It is complaining that the handler for the composer method is being called with Section Cyber. But for the second parameter, he's trying to use this class, which is up providers Cyber composer in the expectation is to have at a city p composers side by the composer. Now it's time to create the sidebar composer class. Let's go back to the documentation in level to see how a composer should look like. From here, we can see that a composer is basically a glass with one method called Composed, in which we passed down a view which is an instance off illuminate view view, and on that view, we called the method with pass down a viable name and its value. So Elizabeth back to the terminal and create a new unit test class with GHB. Listen, make kissed. Let's call it side, but come closer. Test. This will be a unit test going back to the editor in this open up the new unit test and the test annotation and rename it to can compose side where view. I'm going to mark the out in saying that it should receive a call to the use of a message once. And I want this call to the use fermented to return and you use it. But for that I'm going to create one first. So before we finished this, we're going to create a new user using the more than factories and then finished his sentence using and return. Use it. So what I'm doing here basically is I'm creating and you use it in the database and then marking the call to the user method in the out facade, saying that it should be called once and then return the new use that I just create next, I need to create a mark off this class, illuminate the view because within the composed method, we have to make a call to the with method on that class and to do that we're going to introduce mockery up here. I'm going to make a U statement saying Use mockery as him. And here I'm going to save you equals him Mark in past the name of the class, which is illuminate view, have you? Then I'm going to set the expectation that this mark should receive a call to the With method with arguments. Use it and the use that we created. All that is left is to create a new composer class, saying composer equals new cyber composer and then called the compos mentis. On that class, we will pass the mock overview class with this ready, Let's go back and test again. It's saying that cannot find the table uses in. That is because we forgot to make use of the database migration straight. So this ad, that real quick contest again in the can composed sidebar of you were having a nearer saying that class side composer is not found this. Go ahead and create this class right away, and I'm going to put it inside. Http. Composers in the class name will be cyber. Compose it justice again. Same error. But this time is because we have not imported this class in the test before trying to import that class. I'm going to make sure they're the class has the name space, which is app. Http Composer's and then within the test, they simply import that class. You can see the import statement right here. That's this one more time. Now it's saying that the compose method does not exist, so let's create that one within the sidebar Composer. This at a new method called compose, is going test now. It's telling me that the use of method should have been called exactly one times, but it was not called to fix that. I'm going to open the control it real quick, and I'm gonna take this line from here and put it inside the compos mentis. Don't forget to import the outfits. That and let's go in taste one mortar. Now we have another error in the acceptance this Plus we still have the error in the can. Both sides I review composer unit test because this style but composer has not been import First, let's go and check the locks. When we took away that line from the control it and put it in the cyber composer. Now we're getting an error saying that the use of valuable has not been defined in the view . To fix this, we have to pass down that use a viable into the view in the composer side. But we're going to make the compose implementation look more than the one in the documentation type, hinting a view variable of the class illuminate you view so passing, illuminate view, view the name of a better bill would be view and then called Have you with user with the value, Use it this test again. We're still getting this 500 error. There's going check the looks again and again. We don't have the use of other will define even though we passed it down to the view. And that is because we have still not fixed this error up here, where we have an important the cyber composer class. So go back to the composer service provider Class An import, the service provider class from up http composers. There's going test again and we're still having an undefined variable. Use it, which is interesting. We already created the cyber composer class and we're binding that class to the view using the composer service provide, but we're missing one important step every time you create a new service provider. Classing Maribel, you have to register that service provider in the conflict app dot PHP file. If you open that one and scroll down, you'll find an array cold providers. We have to add the new composer service provider to this array. I will have one item at the end for the composer service provider class. Hopefully, if we test one more time, we should get a green status all over. Tests are passing now. In the next lecture, we're going to start creating new acceptance tests for the rest of the features of our application, starting with user administration. 8. Creating Users: we will begin writing our acceptance tests for the user administration part of the system, starting with the user creation. Instead of creating complicated tests that will manipulate forms in the page and feeling forms and then submit those forms, we're going to interact directly with the end points where those forms are supposed to submit. This is called endpoint testing. The advantage of using endpoint testing is that first their way faster and second data require any extra configuration. Let's begin by creating a new test using PHP practice in make test and let's call it admin . You said it's test. The first test will be called can create. Use it. I will start by creating a new user using the factory for the user class. But instead of using the create method, I'm going to use the make method, which will give me a new user but will not save it in the data bits. Next, I will define the data that is supposed to be sent to the end point. I will call this data. It will be an array, and this already will have the name. I'll call this test, use it. The email, the new uses a password. The form also require a password confirmation. So I will name this password conformation, and it's supposed to be the same as best work. Finally, I want to pass a least of many white to my these that are supposed to be assigned to the user. I will call this menu items, and for this I'm going to create a few menu items in the database using the factory. So I will say many items factory many white, um, class. And I want to create three many items finally called Create mint to president. Only the many white in my these as an array. I can just say menu items block and the key i d. And then transformed this to injury. That is all for the arrange park and then for the action. We're gonna get the response which is equal to this acting, asked the new user post, and I want to be able to post to the users you Earl passing in the new date. After the post is complete, I want to assert a few things. First, I want to make sure that the user is redirected back to the users list so I will say response, assert, Redirect users. Second, Every time I successfully create a user in the database, I want to flash a message in the session so I can display when the user gets back to the user list. So I went to a said that response assert session has success. Next, I want to make sure that the user was actually created in the database. And to do this, I seem to say this. A certain database has the name of the table users, and I would like to check against the name, which should be the same s data name and the email, which is data E mail. I'm going to reform it This so it's a little bit more readable. The last thing that I want to make sure is that three menu items that I created were actually assigned to the user. So I will say this third equals I expect three menu items and to find the use that I will just say use it, find one. This will be the user idea. That, it seems, is the only use of that I have created so far. I will then extract the menu items and then counted. Now let's go back to a terminal and start testing. The first area is the lack of the table menu items, and by now we know that this is because we need the database migration straight. How did got in tests again? Now it's saying that instead of getting a redirect code, we're getting a four or four, which is because we don't have a route for this yet. Let's go and create a route. So open up routes where the Ph me. Instead of writing every single route for all of the operations, create update least and delete. I can simply say route resource users and then has the name of the resource controller, which is use it controller. If we check levels documentation, we can see that by simply defining this route. We are actually finding all of these routes in this list. The one we're interested in testing right now is this one. Now let's go back to our 10 minutes and with the route created, let's go ahead and test one more time. Now we're getting a 500 errors, so let's go ahead and check the looks. Now it's telling me that the class user comptroller does not exist. It is time to create our new controller to create a complete controller that adheres to the resource route that we created before. What we have to do is go back to our terminal anti PHP. Have a listen. May controller in the name of the controller is user control it. And then at the end, at the resource black, we go back to our editor and check the up http Controllers folder. We can see that we now have a user controller class and inside it we already have a scaffold off. All of the methods that we need, which are index, create, store, show, edit, update and destroy or we have to do from here is creating implementations for each of them . According to the documentation, the one that we're interested in testing right now is the store method. But let's not get ahead of ourselves and keep on testing. Go back to the demeanor in test again. Now it's saying that instead of I redirect code is getting a 200 car, which is actually an http code for a successful request. And this happens because the controller already has an empty implementation off the method that we're looking for. So let's go back to our controller and for the store method right here. Let's return read. I record to the users. Ural, go back in test again. Now it's saying that decision is missing the expected key success to fix this little back to the implementation. And let's chain one method here called with in the key of this variable in the session will be success in less prints of value. With a sensible message like you, sir created. Go back to the terminal test one more time. Now it's failing to assert that row in the table users matches the attributes Name test user email test at test that car Plus is telling us that the table is empty. Let's go back to the controller and start adding code so that we can create the user in the database. I want to retrieve the user information from the request, but I'm only interested in the name, the email and the password to do this. I simply declare a new viable Let's call it user data, and it's equal to request Onley name e mail and password. Next, I want to include the password before saving into the database. So I say user data pass work equals two be crypt user data password and then to create. They use it in the database. Simply say, use it, create and passed down the user data. There's go back to the terminal and test one more time. Now it's saying failed a certain that zero much is expected. Three. Which means that the user still doesn't have any many white ants assigned to solve this. Let's go back to our troller and I'm going to store the newly created user in available and then called You said menu items. And given that this is the belongs to many relationship, we can call the method that patch and class down an array of many ideas which I can access by calling request get menu items. It's listen back to our terminal and test one more time. Excellent. We have a green status, which means that all over tests are successful, and with this we're don't testing the creation of a new use it. But there is one missing ICT on the controller. We are assuming that the request passed down by the user is always gonna be correct. There is no valuation place in the next lecture. We're going to create tests that will make sure that the information that has been provided by the use of it's actually bad. 9. User Validation: The first thing I want to make sure is that every time a user submits data to store a new user, the name should be required. So let's go back to our editor in our admin user test file right after the can create user list at the new test. Let's call it a user name. He's require for store store being the name of the method in the controller that performs the action off, saving the user in the database. First, I want to have a use of available elsewhere. Will say you, sir, equals factory user class. Make this will give me a new user but will not persisted in the database. Next, I will define the user data. For this. I will just simply copy this section of code from the previous test. We need the menu items as well. So let's copy that one too. But in this case, I'm going to make sure that the user name is missing. The action will be the same as the previous test, so let's copy that from appear to here. In the assertion part, I want the user to be taken back to the users creation for where there will be a never message saying that the user name was missing. Now I could write something like responds, assert, redirect, and then type in users create which will be the, um, well off the user creation for the problem with this is that level one we direct me specifically to the users create u R l. Instead, he would simply redirect me back to whatever you're Well, I waas when I was posting the user information. So instead of making this assertion, I was simply sir, which is actually the http status for redirection. Whenever there is an error in the validation, lateral will flash full of the validation errors in a session variable called errors. So I want to serve that that viable is in decision to do this. I simply say response a certain session has ever's next. I want to assert that there is an error in the ever station viable regarding the name to do this. I say this assert array has king and I'm looking for the name tea. Then we call decision for sad in get the errors variable and transform that to Honore. Let's go back to our terminal and start testing. It's saying that he was expecting the status quo 302 but received a 500 status code instead . And you know what that means is going check the locks. It is failing at a data base level because the user name cannot be new. To fix this, we're going to introduce something called foreign Request Validation, which is basically a class that exposed the method called roots, which returns an array off all of the validation rules that we have to apply to the data that is coming in in the request. Let's go ahead and create this class use in this artisan command here in our terminal list I ph b artisan and we will call it store using you will find this new class on their app. Http requests When you open that file, you can see two methods. One is called authorized and another is called rules. You can use the authorized method to make any kind of authorization logic to make sure that the person that is trying to create a user it's actually authorized to do that. Since we don't have any kind of logic for that purpose, we will simply return true in the rules method, I'm going to add a new validation rules that make sure that the name is required to do that . Simply type in the name King in the validation rule, which is require to use this new validation rule, simply go to the controller, which is user control it and in the store method instead of passing in an instance off. Illuminate. Http request. I want to type hand my new class, which is store use it. I will make the update to the documentation line as well. With this level will first apply validation rules to the data that is coming in the request . And if the validation will fail, it will redirect back the user without even executing the code inside the store method. So let's go back to our terminal in test one more time. Excellent. All over. Tests are now passing and we have a green status. This means that we are not only testing that we can create users in the database, but we're also testing that the information that is coming in the request has all the available information at least a user name. Now let's create another valuation test for the email. This should be pretty simple. I'm going to copy this method right below it to test that email he's required for store. The 1st 2 lines are the same, but in this case, I want to make sure that the email is missing. The action part stays the same as well as the 1st 2 assertions in the last assertion. Let's make sure that we are looking for the Milky. Let's go back to our termina in test again. We're back to this error where he suspecting a 302 status code but is receiving a 500 status code instead. Now it's failing at database level because the email cannot be no to fix. This is going at another validation rule for the email, go back to the store user class and at another key for the email, saying that it is also required. Now let's go back to Terminal in test again, and we have a green steps. There is one more validation rule that I want to apply to the email. I want to make sure that the emails in the system are always unique, and if someone tries to serve meat or create a new user with an email that already exists in the database. The validation should fail, so let's start with the test. Head back to the admin users, test this at a new noticed and call it email this unique for store. I'm going to copy the first few lines of the arrange section of the previous test and paste them here, except that for the user I actually wanted in the database. So I would replace the make with create and in the user data. I will make sure that email that I'm passing for the new user it is the same as the user that I already have a database. The action in the Assertion Park are pretty similar to the previous test, so I'll use copy and paste them here before testing again. I'm going to get rid of the lot of along because it's getting a little too big. Let's go back to terminal and test again. We're receiving a 500 status code, so let's go and check the lock. We can see that it is failing at database level again, but this time it's failing on the unique constrained of the user. Email if you're wondering that I've already comes with a migration for the user stable in that migration is defining a unique constraint on the email field to fix this error. Let's go back to the story user request. And here we are going to add a new validation rule to the email to change multiple validation rules. Toe one. Feel we can use the pipe commit. We're going to use the unique validation rule. But this validation rule takes parameters to passing the parameters of the validation rule . We tied Colon, and the first parameter is a table name where the unique column is found in this case uses the second parameter is actually the column name E mail. We should get a green status with this. So let's go back to the terminal and test again. And just as expected, we have a green steps. Finally, we're going to add the validation for the password, so go back to our test. And here I am simply going to copy and paste. The email is required for store method based. It down here. Rename it too fast. Work is required for store. Remove the password from the user data and then change the key in the last assertion. Let's go back to our terminal in test it, saying that it's missing the expected ever skiing decision, which means that the user was actually created in the database without a password. To fix this error, go back to the store user for request and at a new validation for the password. We want the password to be required. Let's go back to our terminal in test again and we're back to Green. There is one more validation. I want to apply for the password whenever we want to create a new user. I want the password and the password confirmation field to match. So let's go back to our admin user test. I'm going to copy and paste. This whole method basted down here, rename it to password is confirmed for store. The 1st 2 lines stay the same, but in the user data, I will make the password in the past for confirmation to be different. Let's go back to the terminal and test again. The user is being successfully created database with a mismatch in the password implants for confirmation, and this is evident because of the missing expected key errors in the session. Let's fix this by going back to our store user from requests and adding a new validation rule to the password. Notable Oversee Handy Validation Group called confirmed with this validation rule that every will take the field name and try to match it with another feel name with the same name on their score. Confirmation from the use of tests. We know that we are passing that information in the use of date. If they don't match a nearly suspect, let's go back to the terminal and test again. We're back to our green steps. 10. Updating & Deleting Users: before we move on to the tests for updating users. There's something I like to fix on the test that I have right now. If you notice all of this lines, the 1st 10 lines of code for each and every test are pretty much the same. So what I like to do is take those lines and put him in one place so that I can avoid code repetition. And later on, when I come back to the stairs or anyone on a team, come back and read the States, they're actually more readable and easy to understand. So at the top off my test, I'm going to create a new public function set up. My editor did by default. But don't forget to add this lying at the beginning off this method because the based test case has to do some setting up of its own. And if you don't include this will, the rest of the cases might not work. So what I'm going to do is pretty much take this first few lines, a condom and just based on right below here. Now, this user has to be a member off this class. I'm going to make it a private member. I also need to data as a private member. And I will also make the menu items Private Member too. Now, just switch this for this yusor. This many writings in this data and switch this this will. The purpose of the set of method is to execute these lines of code before each and every test. Now, let's go through each test and fix whatever needs to be fixed. For example, the first test. I need to change this to this. You, sir, in this data. And actually, I'm just going to do a global replace changing user to this usage. We're gonna replace all of the instances in that created a problem here. Should have done this before, but that's OK thing that's fixes that I need then change data to thes data. Replace them all and fix this one. Finally, menu items to this menu. I tips replaceable and fix this 1st 1 In the case of the validation tests, I don't want to include all of these data again because all I'm interested in is to onset the name which supposed to be missing. So I'll have to do is say data. Sorry, this data name equals no ensuring that the name will be missing for the evaluation test. I'll do the same for the email validation test saying data email. He quotes. No. Now the validation tests for the email is unique for store. I need a user to be persistent to the database. So all I have to do in this case is just say this. Use it safe, which will take the use of that I have in this variable in just persisted to the database right away, and I'm noticing that many items has been redefined. That's well in the previous test. So I have to go and remove that line from every test coming back to the email. These unique for store Well, I have to do is changed this and see that data email It's equal to this. Use it. Female. Moving on to the password is required. Store. Remove them Menu items line. Remove this Linus Well in. Now that you mention it, I don't think I removed it from this brother. Test Emily's require for store. You have to remove this light to where we are creating user in. Remove it as well from the user name is required for store removed at this user. So way don't redefined it again and is go back to the password is required for store test and change this to say this data best work equal to know for the password it's confirmed for store. Remove this 1st 2 lines and then change this to these data. Best war confirmation equals full or anything else you want. Can be pretty much 123 or whatever it is. But as long as it is different from secret No, let's go back to terminal in test just to make sure that we didn't break anything Great, we're still green. Now we're ready to move on to the test for updating users in the database. So I'm going to create another fist and every call this Ken update. Use it for this and we need the user to be persistent to the database first. So I'll say this. Use it. Save next. I'm going to change some of the data for the user with this data. Maybe we can change the name. I will say this is equal to new name. There's also changed this data E mail make it equal to new email. And finally this change the password. Been said it to new password. Since the password needs a confirmation, we also have to send a confirmation in this data password confirmation equals new password things. Defining new data to update the user is going to be a recurrent theme, especially when we get to the validation. I'm going to just take this lines of data and put them in the set of us. Well, and I will change the name to new data. Actually, I'm just gonna copy and paste this definition here. Over right? This we're here and just changed the values to maybe off the user. Change this to the test. Fast work can be again your past work, same for confirmation and for the menu items. I want to send a different array of I tease just to prove that updating a user can also data many whitens assigned to the user. So after the plug, I would just say pop, which will take the last item off the collection and remove it, and then turned that into an array I'm going to create in private Member called New Later inside all of these array to that? No, let's go back to test and for the action part. I want to say response equals these acting s this user. And instead of a post, I want to make an http put in the u. R L will be you service and then I have to pass the user idea. I can do this two ways. I can just use PHP append to a string or I like this way where I can use double quotes, new service in using brackets I can just past the variable name, Which is this You said I d don't forget the forward slash here into this. I'm going to pass this new data for the assertion part. I want to make sure that once the update is complete, you'll be redirected to the user list so I can see the response a certain redirect users. I also want to make sure that there is a session key for the success message so I can say response. Certain session has success. And finally, I want to check that the user was indeed updated in the database. And for that I can say this certain database has with the user stable. And for the data, I wouldn't use name as a key. In the value will be this your data name and for the email, this new data e mail. And that should be enough to assert that the user was updated. Finally, I want to make sure that the many whitens in this case will be too, since we're sending only two for the object. So I will say this assert equals two and then say you, sir, find one menu items count in parents this year. Okay, Now go back to the terminal in test one more time and looks like I made a mistake because this pop over here will not return on a collection to transform to an array. But instead it will return the last item that was removed from the collection. So I have to do this slightly different. I'm going to take many items. That's a local variable and give it the value of this menu items pluck idea. Now this will give me a collection inside the local variable. Many writers next. I just have to say many writings pup, which will return the last item and remove it from the collection. And then I can just come here and remove this up until here in remove the beginning to just leave it in. Many writings to array. Let's test again to see that fixes the problem. And, yeah, we fix the first problem. And now we're facing with a response. Status. Code 200 is not. I redirect stethoscope again. This is because we have an empty definition for the update method in control. So let's go ahead and see extent right away in the user controller. Look for the update. Metal. Let's return. Redirect users. This will take us to the users. Least Let's go back and test again. Now we are missing the success key from the session To fix that, we go back to the controller and we append to the redirect message with success in this use a sensible message like you, sir. Updated test again. Now we're failing to assert that a row in the table users matches the attributes updated. Yusor updated test that come. It is time to actually update the user in the database. To do this, I want to introduce something called implicit Route model binding. It works like this If you go back to the tear Amina anti Ph. B. Have a listen route least, and look for this line over here. This is the one that makes the update to the use it. As you can see, he's expecting a key user for the i D. And it's passing that into the controller as I d. But if instead with type, hint the Yusor class and passing it variable with the same name as the key in the route in this case user, instead of passing a numeric value for the use already, a lot of it will go and look for that user in the database in return. An instance of the usage. If the user was not found in the database lateral, we return a 404 coat passing not found. With this, we can start constructing the data that we're going to use to update. The user, for example, is creating new data array, and let's say that name equals request. Get name and email will be request. Get e mail. I only want to obey the password if it is present in the request, but it is not required. So in this case, I can say if request has pass work, then I can sit data, password, Equal student, Big crypt request, Get pass work. And finally, I can simply say use it update in passing the data. Go back to the terminal in test One thing we get a new ever saying failed, asserting that Cedo much is expected to I see two problems here. First it saying that the initial count of many writings for the user is zero when in reality I wanted to be three, and the second problem is that is not even a dated that to be to. So let's go back to the test. That's right, this use it. Many whitens attach and we will need an array off menu item. My thesis years so we can just say this. Many of items block I D and then to array. And just with that line it's going test again and made a mistake. Many items is not a function. It's actually a member of the class so removed the grant insists and test again. Now we get a never saying called to on the flight method. Builder at that boat made a typo here in extra t let me go back and fix them. It's actually attach. Okay, Test again. All right, now we're getting the ever that I was looking for saying failed, asserting that three matches, too. To fix this, let's go back to the controller and right after updating the user, let's say you said menu items in this relationship has a method called Sink, which again will take an array off many white to my dese, and we'll sing those ideas to the use it. Any new item in the array that is currently known assigned to the user will be a scientific user in any element that is currently assigned to the user. That it's not in the array will be removed. And here we pass request get menu items. Let's go back to the feminine contest again, and we're back to a green steps. But here we have the same problem we face when creating any use it. We are assuming that the data that is getting in the input is always rally, so we're going to create a set of new test to validate data that we're getting when updating that use it. So let's go back to our test and I'm going to copy the method called User name is required for store. We based it down below in rename it user name is required for update. And here I will say this new data name equals new from the action part. I'm going to cook with this line from the previous test and replace it here and for the assertion part. I'm still waiting for the 302 code for redirection. We're also looking for the ever skiing session and we're also looking for the name key in the air. It's viable. So let's go back to the terminal in test one more time and we get a never saying expected status code three or two, but received four or five. And to fix this error, we're going to create a new form request class using PHP Artisan Main request, and we're going to call it update use it. The reason for creating a new for request is because for the update method, the password should not be required. So let's go back to our editor in blue for the new class inside, http requests off the user remember to change the return value to true for the authorized function, and it's at the validation rule for the name. Let's say it's require. Now we have to go back to the controller and, in the update method, replace the request class with update User. I will all day the documentation like to Now let's go back in test again. We're still receiving a four or five code instead of a 302 So let's go back to our test and see what's happening. And seems like I forgot to include these two lines from previous tests, which will persist the user to the database in attach the menu items to it. And that was giving us problems because we cannot access the idea of a use it that has not been persisted to the database yet. And that was giving us problems because without persisting the user to the database, we cannot access its i. D. And what have failed to notice earlier is that four or five is an http code for method nor allowed, and we were trying to access the users without any I d using the http put method, which is not about let's go back to the terminal and test and that fix the problem. We're back to a green steps. The next thing that we need to validate when updating a user is that if the password is present in the request, it has to be confirmed. So let's go back to our test. I'm going to copy this whole test here, basted below, and there's rename it Pass. Work is confirmed for of the In the arrange part. Let's change the password confirmation. Let's set it to full Just so it's different. Acting part will be the same, and we're looking for the pass work key on the errors session. Eri this test again. We're getting an ever saying that decision is missing the expected key Evers. To fix this, let's go back to our form request of the use it at a new key for password, saying it must be confirmed back to the terminal in test and we're back to win. We will not include any validation for the email field in this case, because when updating, we only allow to change the user name and the password. The last thing I want to do is create a test for the leading a user in the system. This should be pretty simple. Go back to the editor. Look for the can of they'd user test copy it and based it down below. Rename. It can delete user The 1st 2 lines, we remain the same. But for the acting part, I would like to use a the lead request. I don't need to pass any data to this request. In the assertion part, I still want to be redirected to the user least once the user has been deleted. I'm still looking for the success key in the session. But instead of a certain that database has a user with these data, I want to assert the opposite assert database missing and you can remove the last night, Leslie, instead of saying these new data just say this user name in this use it e mail back to the terminal in test. We're getting an ever saying that the response status co 200 is not a redirect stethoscope , and we're getting a 200 because the method in the controller is still empty. Fix this. Let's go to the controller. And I'm going to copy this line from the previous method basted down here instead of user updated. I'm going to say you, sir, deleted. Go back to the terminal in test. Now it's telling us that it's failing to assert that the record with this two values is missing from the database. Now it's time to go and actually delete the user back to the control. It I want to use implicit route model binding again. So instead of passing the I D. I'm going to type hand, you said in passing the viable called user. And then here we simply say, you, sir, delete I was off. They did of commendation nine as well. No, back to the terminal in test and we're back to green in the next lecture. It's time to get some practice. I want you to create the tests for the Menu Items Administration part. Remember that we need tests for creating off dating and the leading menu items in the system, as well as any tests for the elevation off those actions, you can use the test that we have created so far as an example. I highly recommend that you try and solve the exercise by yourself before moving on to the next lecture, where I will go over the proposed solution for the exercise 11. Installing Admin LTE: for this lecture. I'm going to take a step away from the regular test because I want to start fleshing out the visual interface of our project. And that has nothing to do with test for this project. I'm going to integrate level with a free dashboard. Call admin, lt. I'm going to walk you through the process of installing and integrating this admin lt dashboard into your project. First, open up a terminal window and make sure you are inside your project folder in Seedy into the public folder. Then type Broward Winston add mean death. Lt and he entered. Remember that we are working within the homestead. Beautiful machines. So the bowel executable it's already and stop. This will take some time to install. So I'm going to pause the video and come back when the process has finished. Now that the process has finished, go back to your editor and open the public folder and you should have a new folder called Power Underscore Components. Open that folder and look for the distribution folder dissed for sure, and within that folder competed CSS I am G ingenious folder and based in right at the level off the public folder. We're going to warn you about some fires that already exceeds there. So just overwrite. Among if you are using get huh? Make sure you at a new line to the git ignore file so that the power underscore Components folder will not get propagated to your source control. Next, I'm going to use that about two scaffold, the entire authentication system. So go back to your terminal and make sure you are in the root of your product folder Anti PHP. Make out. Go back to your project and check the resources The useful. There should be a new folder called House and inside it we should have a logging that played out pH. Being we're not going to use the register view food spread in the next lecture. I'm going to modify the logging to integrate the new admin lt. Dash work in the interest of time, I'm going to include a couple of layout files in the resource section of this lecture so that you can download them and put them inside the abuse layouts holder. Once you have that ready, you can go into the next lecture 12. Login View: you should have downloaded two files from the previous lecture. Those two files were layout files that should have been put within. Resource is views layers. 1st 1 is admin Dash lt Doc played dot pH being, which is basically an HTML found that would serve as the style for the rest of the project . Also, you should have downloaded this other file called al's dot blade that PHP, which will serve as a stand for the logging bitch. Next, we need to copy two folders found in public our components on mean dirty. You should copy the bootstrap folder and the floggings folder. Copy those two and paste them in the public folder. So inside your public folder, you should have a Boonstra CSS. I am G. J s and plugging folder. Now, in the interest of time, I'm going to include the complete logging view in the resources section of this lecture. So go ahead and download that file and place it inside. Resource is views out replacing the current logging that late that PHP. Lastly, we have to make a couple of modifications to the Rouch with fire. When we created the scaffold for the authentication, a lot of added these two lines within one more line at the top, so that we redirect users directly to the log in page when they access the application. So just type route, get forward slash comma function, and here I'm going to return, redirect and take the user to forward slash blogging. Now open a browser window, another gate to admin panel that a PP, and with that you should get this nicely style logging view. The next lecture. We're going to modify the dash for view where the users will be redirected ones that is signing into the system. 13. Dashboard View: in this lecture, we need to create the actual database that we're going to use in the system because if you clicked signing from the log in page, you're going to get an exception saying that the table users does not exist. So let's go back to termina and simply run the migrations that we currently have in the system by type in PHP. Have a listen. Lay great. This will create all of the tables in the default homestead data vis. Next, we're going to use PHP artisan thinker to create a new user in the database. We're going to use emotive factory for this. So just that factory up, user class create and here we're going to pass an array of data with name. It's called this admin user email. We're going to copy it from here. I'm going to give it a value of admin at admin pennant dot a PP and by the folder, a password will be secret. So I'm going to leave that out hit. Enter now let's go back to the editor to make some modifications to the logging controller . So open up a city comptroller's out blowing controller and look for the redirect to where? Change that to dashboard in the interest of time. I have included a few files in the resources section off this lecture. 1st 1 will be indexed that played a PHP that you should download and replace the one inside . Resource is views dashboard. Finally, you should download both Heather that blade that PHP in cyber that blade that PHP and put them both inside. Resource is the use section. Make sure your override the core inside by our dot blade of PHP inside a folder. Once you have that ready, open up a browser window and go back to the logging page, typing the admin at Admin Planet that a PP and the password will be secret and he designing . But if everything goes well, you should see this view right here. In the next few lectures, we're going to create a user interface for the use of administration and the many whitens administration 14. User List UI: for the use of administration. I want to create a view where I can see all the users of the system for this. I'm going to create a small test and I'm gonna call it Use a released first. I'm going to save the use it into the database using this you said safe. Next. I want to visit the user list. So I would say response equals to this acting us, this user get forward slash users. And finally I went to assert a couple of things. First, I want to be able to see the user in the list. So I would say response. Yes, sir. See? And here I'm going to use HTML entities to avoid any errors with strange characters or quotes in the names. Next as this you said name. And in order to transform single quotes into HTML acceptable characters, I have to pass down a flag called E n T. Girls. I will do the same, but this time with the use of email. And finally I want to make sure that the view gets there right variable. So I'm going to say response a serve you has and I want to make sure that I passed down a valuable cold users. Now let's go back to the terminal. Make sure you are inside your folder intestine use in PHP unit. We get our first error saying failed, asserting that empty string contains this name, and this is because the matter in the controller is empty. So let's get back to the controller and look for the Index Smith. The idea here is to return a view, so I'm just going to say Return Review Uses Index and I am expecting a different ever because this view doesn't exist. So we're back to the 10 minute just again, and here we are, getting a bunch of HTML, which looks like an STM A for a neighbour page level. So I'm gonna check the locks real quick, and it's expected unseen, never saying that the View uses index was not found. So let's create that view inside. Resource is views on here need to create a new folder called Users, and inside it I'm going to create a new fan called Index Duck laid that BHP Let's leave it nt for now and go back to test, and we're back to this error failed us everything. That empty stream contains this name. This case we do have a view, but the view is empty. So now it's time to create a viable with the use of released in Pass it Down to the view. So let's go back to the controller. And here I'm going to say users equals the use of more than get and then past that to the view. If I go and test again, I'm going to get same every because I'm still doing nothing with that variable and that's expected. We get the same error message. Now it's time to go and start filling up the view with the logic to this. Play the user list. Let's go back to the editor and I'm going to use the dash for view as the base or start for my new view. So I'm just going to cook everything in here and pasted inside users in the double bladed. PH mean I'm still extending from the same layout, but I'm going to change a couple of things inside the content section. First will be the title. In this case. I want this to read users. Description will be user administration and inside the breadcrumb. I'm going to change this to dashboard and then another item with class active. And the label use is now inside the main section here. I'm going to create a row. So def class role, and then a column that is going to take roughly half of the screen. So def Close Grill M D. Six. Next, I will create a deep class box, which is a class inside the Admiralty, which will create a white box for a contact inside the box. I'm going to create the box body with def class boxy body. Finally, I'm going to create in the table with class table in table border there I will bad ahead it to the table in the heather line. One have the idea of the user, the name in the email finally, for the body off the table, our creating for each look and either rate over the use that is valuable. Yes, use it. And for each iteration, I'm going to display a row with the use of writing the user name and finally, that you said remit. Let's go back to the terminal in test and I'm getting an error. Someone check the logs real quick, apparently, and still not getting the viral users someone other back to the controller and yet made a type of the name here. It's test again, and we're back to green no over browser window and navigate to admin panel that a PP signing with the use of re created in the previous lecture. Now in the URL, navigate to the users list. There you have it. We have, at least of all of the use of in system in this table. In the next lecture, we're going to create the user interface that will allow us to add new users to the system . 15. Create User UI: to create a user interface for adding users to the system. I'm going to start again with a small test. I'm gonna call it you, sir, create. And in this case, I don't need the user stable database. I just need to use it as the logged in user to visit the u R L. So I'm just gonna copy the acting line of the previous test and change the euro two forwards less users forward, slash create And the only thing I'm interested in checking is that the view will get a list of many writings that can be assigned to the user when creating. So I'm going to say response the serve. You has many writers. Let's go back to the terminal in test. Really never seen that the response is not a view. So let's go back to the controller and for the create method. And it's a return of you so turn view. In this case, the view should be called users create. Let's go back to the terminal interest and we're getting the same error. But in this case, I know that the problem is that the view doesn't exist to prove it. You can check the locks and there you will find this. Ever view Users create, not found. So let's create a view inside resources, views, users we're going to create a new PHP file could create the blade, not BHP. Let's go back to Torino in test Now we get a deep than ever saying failed a setting that Honore has has the key, many writings. So let's go back to the control it and passed down that menu. It's invaluable to the view. And here one see menu items equals menu item motile glass get and then passed down to the view. Now, if we go back and chest right now, we're going to get a green status. That is because the view has the menu items, but still, we're not doing anything with anyway. List estimate. Sure, even though we get a green status, this is not exactly what we want because we're not doing anything in the view and the view is empty. So I'm going to make one more assertion in the test. Mr. Make sure we're in the red plates. So response a search. See? There wouldn't see a title gold create. Use it. This will not contest again. No. You never saying Fateless. Earth in the empty stream contains creating user. And now it's time to add some content to the view. I'm going to use the dodgeball view again as a model, So I'm gonna copy everything and based it inside users create the bladed PHP. And for the title, I'm going to change this to create user. And the description would read, Create new User. We're gonna change this link to dash work. I will have another element with a link to the user released. So for users, label users and finally another element quick class active with the label create use it the main content again I'm going to create in your row and then a column that will take half of the screen. So if close call M d six and then a box with the glass books, then I'm going to create a new form with grow for the action will be users and miss. It will be post for any pause method. The C inside field is required, so I'm gonna add it with CS R F Field, which will render a heat and field that will be used by letter over to check for cross site request forgery. Next will be the box body, the class boxer body and then a New Def Class former group. And if you recall from previous tests, we know that when we are creating users in the system, if there is any errors in the valuations, for example, the name being empty novel is going to ready right back to this form in inject a viable ever seen it. So I'm going to use that ever is viable to highlight current form field in red. And I can do this by adding the class has errors to the former group so right next to the form group. But before the end of quote, I will add a space double brackets and then I'm going to check if the Evers Valuable contains the key name, so errors has name. It's so I will display has errors which will upend that class to this glass statement here . Otherwise, 70 stream. No, I can use this method in the ever terrible because the every battle is not just an array sexually an instance off the message back class, which has a method called, has that we return a bull if the message exists for the given key. Now let's go back to the view. Close the deep attack and here I'm going to add a new label Believable before name in the content of label will be name right below. I'm going to add a new input. It will be type text the name of the name class for control and then for the value I'm going to use levels helper method cold and then pass a key name if I attempt to submit this form and there is any validation errors on any of the other fields. When edible redirects me back to this form, this old method will return the previous value that I had type for the input so that I don't have to type it again Now, right below the input, I want to display a helpful message that will display the ever messages off any validation errors that occur. So I'm going to say if errors has name, I'm going to this play a span with class help, look! And then the ever message in both letter so strong ever's first name first will display the first ever message for this keep. That is just in case there are many messages or validation. Evers. What? The same field. Now, to save some time, I'm going to copy this entire DIF class form group, then paste it right below it and then change some names to include the email field. First line will be e mail here. Then the labels exchange that two female the input type will be email name will be seen as well. Quarter the old method exchange dad as well to email. Finally, she insists to email in days to demon. So far, we have name email, you know, that's left is password and password confirmation. So again, I'm going to copy this entire DIF basic below. I would change this first line to password enable password input type, pass work name will be password. And in this case, I don't want to display any old value for security. This sheik would be made against pass work and finally password. All that's left is the password conquer mention. So I'm gonna cook this base that don't you know, And for the possible confirmation, we don't need any error checking because any ever since password computer mentions you will be delivered in the past working. So I'm going to remove this whole chick here. I'm gonna change the label to classwork. Confirmation the input title, the password. The name will be password on the score conformation, and then remove this whole block here. Now we have to add Oneness Field to select the menu items that can be assigned to a new user. So I'm going to creating a thief class form group. Then you label it takes many years or rather, menu items, and I'm going to use a select multiple input so that the user can select multiple menu items in one go. So select name. And I'm going to name this menu dash items and is very important that you had a couple of angle brackets at the end so that a lot of it will treat these as an array glass for control. And to make this a multiple select field just at multiple at the end. Next, I'm going toe reiterate over the menu items and at items to the select in. So, for each many writings, as many waiting well here, I will display an option with the value many writing I d for the Texan will display that many writing text. No, Right before you close the four, I'm gonna add a new digs with glass box food or and inside it I'm going to add a buckle off types of meat in Class B TN VT. In Dash Primary for the label would take super. Let's go back to that that I mean a test again just to make sure I didn't break anything. And we're back to green, you know, from the user least I don't have any way to access than before, so I would like to add a button that allows me to go to the create for So we're back to the editor and look for the Users Index that lay the beach being and right below that, the class box this at another things with class books headed inside it. Another deeds with class box tools, food right And here I'm going to create a link. There will take me to users create, and I will make this link look like a battle with class Bt in Bt and info in Bt N. S M. As in small, just to make it look a little smaller, and for the label, I would say create use it. This goes back to the browser's refresh, and it looks good, except that the battle seems to be cutting in front of a table. Little bit in, apparently is because the box heather class it's a little too small. So I think adding a few more pixels to the padding will fix the problem. 15 will be OK, so let's go back to the view real quick that users index and at the top, I'm going to add or override a new class box. Heather and I'm gonna set the padding to 15 fixes. Let's go back to that. But I was set and refresh. Yeah, that looks better, but it would look a lot better if I had, like, an icon of plus Sign next to the label. Let's go back to the view one more time in right next to create user It's at and I class, if a if a dash. Plus, this is an Aiko provided by the phone iPods included in the admin lt dashboard. So let's go back to the browser refresh one time in. Yeah, that looks a lot better if we click on that button, we should be taken to the new form to create a user. Now this does this form just to make sure that it works. We can be certain that thanks to all of the taste cases that we have written so far, we should be redirected back to the form. If there is any effort in the validation, so clicking the submit button will take us back to the fore, and it is displaying the ever message for field. Although I'm not seeing the field highlighted red as I expected. Let's examine what, maybe a minimum stake on the name of class. So I'm just going to modify this attributes instead of has ever switch, say has ever. And yet that was a problem. Let's go back to the view changed that real quick. But when I create that later Ph being and instead of has errors has just changed. That, too, has ever to go back to browser and try to submit the form again. We found the name Great. Now we're getting all of the valuation errors, the main fields wired, the email is required and the fast work is required. This type a new user go to school it test. Use it with the email test at test that come password. Let's say 12345 And just make sure this working I'm going to type a different password confirmation submit. And as you can see, we get the error. A suspected of the battle conformation does not match. And using the old method, we get the information that we type before so that we don't have to type the name and the email one more time. So I'm gonna say 12 people five again in passport confirmation with same 12345 And we're not going to assign any menu items because we don't have any system. Currently, Click Submit in just as expected, were taken back to the use released. And now we have another user in the system. In the next lecture, we're going to create a user interface to modify the user information 16. Update User UI: it's time to create a user interface for updating users in the system. As always, we're going to begin with a test and we're going to call this test user it In this case, we will need the user to be saved in the database. So I'm gonna copy this line from two tests before basted here in. Additionally, I'm going to attach a couple of many writings to these users. I will use the menu items that are already assigned to this new data on the many white and scheme, which is a subset off these many writers. So I'll just say this use it. Many writings with Parent is this Attach this new later menu items for the action part. I'm going to copy this life from the previous test, basted here and then modify the, um, well, first, I'm going to change this to double quotes, forward slash users forward slash open and close brackets. This user I d going forward slash edit for the assertion part. I want to make sure that I have a few valuables inside the view. So I'll say response. A certain view has first of all, I want to make sure that you has the use their available. I also want to make sure that the U has the least of menu items, and I also want to make sure that the view has a least of many lifetimes that has been assigned to the user so that they can be pre selected on the select input. I'm gonna call this user. Many whitens also just like the previous test. I want to make sure that I can see the correct title in the page. In this case, it's going to be update user, and I also want to assert that the user information will be displayed on four. So, for example, I want to see response a certain scene. This you said name. But I want to put this again inside HTML entities to avoid problems with single quotes. In other were characters and specifically for single quotes. I have to pass the flag. E n t. Quotes Next. I want to write a couple of assertions to test that the menu items that are already assigned to the user have been pre selected in the multi select import. For this. I'm going to write response, asserts See, And here I'm going to pass a string representing the option tacked inside the select input , which should have a value, equals two, and this should be actually double close. So to represent a double quote inside a double portrait string just at a backslash double quotes, you know, and another one to close it down. And here the value should be. This knew they many writings and within the menu items array and looking for the first item . And right after this backslash double quote, I want to write space Select. I'm going to copy this line and paste it below it. And instead of first item, I'm going to look for the second. Write them. Let's go back to Termina in test. The response is not a view, and this is because the control method it's still empty. So let's go back to the control and look for the area method and has returned a view. Return view users and let's go back to the terminal in test. We're still getting the same error message, but we know that the problem here is that the view does not exist and that can be corroborated by looking at the last every message in the law where it says view users edit , not found. So let's create a new view. Inside. Resource is views users, and it's call it and it that blade that PHP back to the terminal in test. Now it's failing toe. Assert that Honore has the key. Use it. This basically means that the use of a viable is missing in the view. Let's head back to the controller. And here we are going toe inject an instance of the user mother using implicit round more than binding. If you're not sure what to call the variable here, just go to the terminal and do PHP Artisan route. Least look for the users edit route and here we should pass a variable cold use it. So go back to the controller Typing the user model class and called a viable used. I will update the documentation line, reflect changes and remember, with implicit route mother binding lateral will use the I D passing in the road. Go to the database and look for a user with that i D and injected here in the use of available. If the user was not found in the database. LaTavia we return a 404 exception. Next, I just have to pass this user valuable to the view. Let's go back terminal in test. Now we're missing the menu items viable in the view, so go back to the controller and it's creating new viable called menu items equals two menu item. Get this would get all of the menu items in the system and put them in this world. Next, I will pass that variable to the view just one more time in the terminal, and now we're missing that uses menu items. Let's go back to the controller to the sign that barrier. In the case of the user menu items variable. I want to pass that down as an array of I DS, and I wouldn't explain why I want to do that when we get to the But for now, let's you define a new, viable cold user. Menu items equals two. You said many whitens block I D. In this turned that into an array, and actually I have to prefix this with the table name menu items. Otherwise I D is going to be an ambiguous call him. When the queries made to the diabetes finally despise that view. Go back to terminal in test. Now it's failing to assert that empty string contains off the user because of you. Then we created It's still empty. Let's go back to the editor to start adding content to the view. I'm going to copy the contents of the creator blade of PHP and then paste them inside the new editor blade of the age mean and make some modifications to it. Put example instead of create user that want to see off the user as the title before the description, say update, use it. The last item in the breath grounds should read. They use it. I'm going to use a technical method spoofing In letter, I will add a new input tight, hidden and given a name off underscore method in a value off. Put this way, even though the four method is supposed level, will interpret the method as a put method. If you don't include this field, a lot of it, we return a method nor allowed exception. Next, I'm going to remove the email field because we are not allowing any user to change that email once they have been created in the system. Only their user name and password. Next for the value instead of using old name. I'm going to use you, sir. Name both password and password. Confirmation should be empty. And inside the loop off the menu items. I'm going to make a decision whether this option has to be selected or not. So right after these double quote here at a space opening good double brackets and type in array The current many white I d comma yusor menu items This will return true if the current many white um I d is found in the use of many items, which is the least of menu items that has been assigned to the user. Give that is true. I'm going to return selected or a name to stream other ways going back to the terminal interest. And we are back to read, just as we needed a way to access than you create for in the previous lecture. Now we need a way to access the update for, and what I'm going to do is in the user list. I'm going to turn the user name into a link to go back to the editor and Open Resources Views Users Index. And in the second column I'm going to add a link which should take him to users. You said I d it And then close attack. Go back to the browser and French. You know the user name. It's actually a link to the edit for this click on the second user. And as you can see, the use of information is pre populated for name, password in passport. Confirmation are empty and scenes. We don't have any Man United's system. This is empty as well. This test is by changing the user name to you, sir. Just user off date when it hit, submit and we're getting a method not allowed exception. Oh, I know what the problems go back to the view, and since I copied and pasted this from the users create form, I forgot to update the you Ariel for the action of before, which should be users forward slash. You said I d. Let's go back to the browser. Click on the back Buttle to take us back to form. Refresh the form to reflect changes. Stainless changed the use it to test user update in click submit and apparently I have very bad memory because we do allow users to update their image. So let's go back to the editor and for the creator played pH being I'm going to copy the email form group and basic right below the name form group right here. I'm going to change these old method with you, sir. E mail. Now let's go back to the browser again, kid. Back refresh. Changed the name to tense. Use that old date again, and I'm going to change the email to test update that. Does it come and hit? Submit? There you have it. The user has bean of data system. The next in last feature of the use of administration system is the ability to delete users . And we're going to create that in the next lecture. 17. Delete User UI: The last feature that I want to implement for the user administration is the ability to the leader user that has been already created in the system. For that, I'm going to add an extra column in the use released with a delete back. And as soon as I click that button, the user will be deleted. So let's go back to the editor and open Resources Views Users Index. Don't blade that PHP right after the email column in The Herald. Let's add another heather with the label delete and also below the email this at another column and inside that column at the form with the action forward slash users for were slash open and close double brackets. User I D. And the method will be post at this year's Are a field with levels CSR if field method. And here I'm going to use methods spoofing again to simulate a delete myth instead of a post. So at an input type healing name, underscore method value, delete and right after that input, let's add a button. Types of meat is your class DTN, BT and danger to make it a red button and also Bt and dash asked him to make it a little bit smaller. And for the label of the bottle, I'm going to use an anchor. So I class F A Space F a trash, which will give us a trash item. Let's go back to the browser, then refresh. And if you click on this But here the test news rubbed, it should disappear from the list. In the next lecture, I want you to get some hands on and create the many whitens administration use of inter fates. You can use the use administration interface as an example. Remember to use test driven development and always create a test first and let that test drive your developed.