‫All right.
‫So now we want to take care of the edit.
‫We want to edit the listings.
‫So basically there's two phases to this.
‫One is to create the edit form.
‫And we need to fetch the data to put in that edit form.
‫And then we need to handle the actual form submission which will be the update.
‫Okay.
‫So in our listing controller the edit method will just show the form.
‫And the update method will take care of the submission.
‫And we need to create two routes for that to happen.
‫So let's go into our routes dot PHP.
‫And I'm just going to separate the post.
‫Anything else from the delete I'm sorry from the get.
‫So we'll have the gets up here and we're going to have a form sorry a get request to get the form or
‫show the form.
‫So I'm going to go right above this.
‫You want to keep the the ID at the bottom because you don't want.
‫For instance if I say slash edit and I put it down here, I don't want it to think edit is my ID, if
‫that makes sense.
‫So so let's say router and this will be a Get request.
‫And the the URL is going to be slash listings slash edit slash.
‫And then we want the ID.
‫So that's how we know which one we're editing.
‫No money sign.
‫All right.
‫So that's that's that.
‫And the method that is going to be called in the listing controller is going to be called edit.
‫So we want to say at edit.
‫So that's the form.
‫Now when we submit the form it's going to be a put request.
‫So let's say router and then put.
‫And that's going to be slash listings slash and then the ID.
‫And then the method will be.
‫In the listing controller and it's going to be called update.
‫All right.
‫So those are the two routes that we need to add so we can close this up.
‫And let's go to let's see controllers listing controller.
‫And down at the bottom.
‫Actually, you know, what I'm going to do is copy the show method because it's very similar to that.
‫Because we need to fetch the listing to show in the form.
‫So I'll just grab this whole thing right here to show.
‫And let's.
‫Paste that down at the bottom.
‫Make sure you're still in the class and we'll change.
‫Where is it?
‫We'll change the comment here.
‫Let's say show the listing edit form.
‫Same params.
‫We're going to change the name of this from Show to Edit.
‫We're still getting the the ID from the URL.
‫We're creating this params array where.
‫Fetching the listings.
‫I'm sorry.
‫We're fetching the single listing from by that ID in the URL.
‫Check if it exists, show the not found if it doesn't, and then load the view.
‫Except we want to load listing slash edit.
‫And we're going to pass that listing into it.
‫So it saved that.
‫And.
‫Just to make sure this works.
‫And we're getting the listing.
‫Let's do an inspect and die right here.
‫And let's pass in listing.
‫Just to make sure that works.
‫If I go to slash.
‫Listing.
‫Slash, edit.
‫Slash.
‫To.
‫And there we go.
‫So we know we're fetching the data.
‫All right.
‫Now on the show page there's an edit button.
‫But right now it just goes to slash edit which obviously isn't what we want.
‫So let's go to the show view and where we have the edit link right here.
‫Let's change it to slash listings slash edit slash.
‫And then we want the ID so we can get that with listing.
‫I'd.
‫And now if I save that, reload the show page and edit.
‫You can see it's going to the right place.
‫Now as far as the view goes, we need to create it.
‫So in listings let's create edit dot view dot PHP.
‫And I'm going to copy the create view because it's very similar.
‫So let's copy everything in the create and paste it in the edit.
‫And then just change a couple things here.
‫Get rid of this comment in both of these files, actually.
‫Okay.
‫And then I'm going to change create job listing to edit job listing.
‫And let's see, we can get rid of this comment here.
‫And we can get rid of it on the create as well.
‫Just clean it up a bit.
‫All right.
‫Now in the edit.
‫Let's see.
‫We have our errors.
‫Now the fields here, the values are.
‫They are formatted as an associative array, and that was fine for the create because of what we passed
‫in.
‫We did pass in an associative array, but here it's coming right from the database right in the controller.
‫We're getting the listing from the database and then we're passing it in.
‫So we want to use the object syntax the arrow syntax.
‫So here let's let's get rid of that and put an arrow here.
‫And then get rid of that.
‫And we just want to do that to all of these, all these values.
‫So description.
‫And we have salary.
‫What else?
‫Requirements.
‫Benefits.
‫And let's have the benefits tags.
‫Tag's company.
‫Address.
‫City.
‫State.
‫Found.
‫And email.
‫Okay.
‫And then let's see what else do we need to change here?
‫So the cancel button.
‫Let's have that.
‫Let's have that go back to the actual listing.
‫So we can do that by doing listings slash and then the ID, so we'll just go listings or listing ID.
‫Okay, so that should bring us back.
‫And I think that's it.
‫So now let's save that.
‫And if we go to the well we need to get rid of that inspect and die.
‫In the edit method and then let's reload.
‫And there we go.
‫Edit job listing and you can see the data.
‫It's all there.
‫All in the fields.
‫All right.
‫So that takes care of the form display.
‫So in the next video we're going to go ahead and make it so that we can actually edit some some data
‫and submit the edit form to the update method.