Laravel 8 Tutorial | Eloquent ORM Edit,Update Data With Image & Without Image Part 32

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello friend welcome back in a previous video we successfully display our edit portion right that means here from here if you want to edit any your brand then you can edit it from to this area so if you click on idi then it will be directed to the edit and the specific one of the id and this display your brand name and the images and also it display that existing image so now i want to do i want to update these portions like here if you want to update this brand name if you want to change that images how can do that work in this video i will show you that things with a live example so for doing this we have to have to create on your form that means when you click in particular this button automatically should be put some of the action into the form area that means there is our update button and also they have one of the form right so now we have to do have to work in particular this form area so i have already have updated that url is a brand and the update and with a specific one of the id it will be updated so we have to do have to create this url and before create this url also here you can see that the post method so for the post method as i told you friend we have to do we have to add that nc type right so we did the same things for into the index maybe uh into the index they have also on the form you can see that is actually the nc type so make that sure you add that nc type better i copied from here and now i paste it so that is our images so when you upload any images our decency type will be needed without this nc type form data you cannot update any images right so make that sure you add this part and also here one things like when you update your new image right so when you update your new image our old image will be needed because of all specific these two id they have already existing one of the image so here we have to do we have to replace it right so we have to replace it so for the results here i want to do i want to take one of the hidden field for getting out this specific id so if you want to get it that means here after this csrf okay so after this csrf i want to do and to add one of the input field everything will be very clear to you why i'm actually using it i take on the input so that will be the input field why it's actually not giving me any instruction let's import so that is input okay so into the input type i want to do and to make it type will be as a hidden type okay i make it as a hidden type and into the hidden type i name this field i named this field as a whatever he wants right now make it as old underscore image okay so into the old image area i want to undo at that value so i want to add that value our value will be whatever value will be our existing image so our existing image i have already discussed about that things with you with these brands that will be our existing image right so because of all from here i get all that our data with these brands so now i want to do uh here into the value area with this uh brand i want to do i want to add our image now our existing field image our field name as a brand image so that will be our existing image right so i want to add that our field name as a brand brand underscore image i hope it's very much clear to your friend so this field is the hidden field so this field will be not visible because but here which will be needed uh i will show you like right now first of all i want to join to create our this url so and also they have one of the id now go to our web route into the web route that is our update portion so here better i copy it okay and that will be as a post method make that sure that is actually post method and into the edit i have already updated it as a brand update with a specific id so name it as a brand update and then they have the id now in our brand controller i want to create one of the method as an update so now we have to do we have to create it right so now go to our brand controller into the brand controller after that edit i want to create another one as a public and then function sorry function and then our update so i want to do and add it and also when you're working with the update as i told you friend we have to we have to actually add that request remember so we have to add that request request and the dollar request so that is a pretty much same format and also that have one of the id because of all here you can see they have also one of the id we have to also add that our requested id so that will be our requested id so now i simply add it in particular that area perfect and after that if you want to add some of the validation you can add that validation and everything will be just like our um just like our this portion that means how we store data right that means i have already created around the store method as the store band so now i copy everything okay so that is actually one of the first bracket so i copy everything so there is return so i copy everything better okay i copy everything it will be just like that same here i copy it and now in our brand here in particular that position i want to do and paste it perfect so for the validation here i want to do and to change that validation like here we don't need that image okay because of all uh here we don't add any image validation because from to this position we have to actually updated that image right so image will be as open under the brand name unique right now we don't need this unique brand name because of all some of the time user may want to update only the images not the brand rather than it should be actually gave some of the validation message that this brand is already exist right so this type of validation should be display but i make it as a required and also i make it as a minimum four character and then brand name required and then minimum character it should be display brand longer than the four characters so that is our validation perfect so here we don't need to change anything is now great and then our band image so brand image will be just like that same okay that will be that just like that same our band image and then it will be created one of the unique id and it should be star and mr to lower and then get the client extension it will create one of the unique id and then dot that extension uploaded with the same folder everything will be same okay so friend here we don't need to do anything so here we don't need to do anything only here we have to do when i want to do ah that means when you new a new images will be uploaded our old image that means into the database in our folder here already this picture is saved right when i want to replace this image automatically this will be replaced by our new image so i want to do this image will be unlink okay this image will be unlinked and then here our new image will be added so if you want to do that work so for doing this um here okay after this after this here i want to have to take one of the variable i take one of the variable as a old okay old underscore image oh sorry image so old image means our requested that means are requested and with this requested here you can see friend i have all already declared one of the field that is one of the hidden field and i take that name as a old image so this old image means what this old image means which image is already existing in our brand image position that means band image field right so into the brand image field they have already one of the images exist so that is the image i take it so that is our fill name as the old image so now i want to do and to add that or this will be our this requested old image okay friend i hope it's very much clear to you so now i simply add this part okay and that this out so now i want to do i want to actually unlink this that means i want to remove this our old image so if you want to remove it so here that is our old image i take the things with this variable so now i want to do i want to unlink it that means here there is a before that was actually insert for insert this data so now first of all i want to under unlink okay i am to unlink that is one of the building function of laravel and here i want to unlink which one i want to unlink our old image which image is already exist in our brand image area so here i want to do i want to unlink it right friend and then there is a brand not into the brand area they have also one of the id that means this requested id right so here we have to do we have to add it that means um that will be not insert here i want to do before insert it i want to actually find it that is a find find our data that means our requested id so our requested id will be as this one and when will we get this our requested id then it should be update so i simply have added that our update function okay and then our brand name will be updated and our images that brand images will be updated and then the create that created ad will be updated perfect and when it will be updated it should be returned redirect to the back page with successful message as a brand updated okay updated successfully so this type of one of the message it should be display so that's all you have to do friend i hope every part is very much clear too now let's first of all check it now click the save all now go here refresh it so now it's showing unexpect syntax error unexpected brand so here you can see i didn't add that semicolon so here you can see also showing on the error so that is our link here i didn't add that semicolon okay so make that here you add the semicolon and also here um that is our image here i add it perfect now let's check this out again click the save all error arrow is gone click as a refresh yeah it's not perfect so now i want to do i want to update out this gucci okay and like if you go to brand that is our test if you guys eat it 70 does it test one okay or guest one and also i want to update that our choose image so now i want to do one to choose another new image that means this one click as open so that will be our new image right so now i want to do this will be replace it that means it will be replaced and it should be replaced with our new image so now let's do that work there's the update yes you can see friend it's now updated that means that is our update brand is updated and also you can see image is updated so if you go here yes you can see friend our old image is replaced with our new image so that is the things i want to do so for the reasons here i take our these existing image and this existing image i make it as unlink that means it will be remove our old image and our new image will be updated okay so you can see there is our brand image new image will be updated and after that that should be directed to our back page with the success message so better i want to do and to make it as a if you want to display it in same page then you have to do you have to actually work in our back page means our edit page right so into the edit page here you can see there have no message so better i want to do from the index i want to actually get this image that means if this have any success message you should be display so after that edit brand better here okay after this here i want to turn to display it click the save all and now go here go to the brand and now edit it and change it as a gucci one choose that images i want to choose this one click as open update image here is now showing as a brand updated successful and you can see updated name is updated image is also updated and that is our existing image is visible if you go our folder yeah you can see it's not replaced with our new image not it's inserted again with that new image so perfectly it's now replace it but here one things you have to update actually both of this because here i have already had some of the validation like if you only want to update that image like i choose this image click as the update image now you can see it's now showing as a brand if updated successfully that means image is updated but here if you want to this one that means i only want to update it that name that means this name if you want to update it click as the update image now you can see it's now getting some of the error it's because of all here i add some of the validation so i want to do um i want to make it as a only when i one only want to update it that brand image and then after that if you want to update that brand automatically it will be updated and rather than if you don't want to update it um the brand name or the images then you can actually choose it so how can do that work you can do it very easily friend here you have to do we have to add on the simple condition i show you into the brand controller here so here after this uh that is our brand there is a brand name so after this here i want to do and to add one of the if condition okay i add one of the if condition and the if and also here we have to do we have to add another one as the else so into the brand um that is actually that means if there have any image okay that means if they have an image then you just add that action so i want to add this action okay and then else else it will be do another work okay so that is our if condition and the else condition so into the if area i want to do and to take everything i want to take everything i copy it or cut it from here and if they have any brand image then it should be updated this portion okay that means it should be executed or this portion perfect and else else you should do the another things else it will be do just only updated that brand name so that is a brand name is this one so better i copy it i copy all things from here and into the else area it will be only then updated and that's brand name not the images so i simply remove that image okay so that will be removed perfect so also here it should be back to the word same page also it should be back to the same page and here there is if condition and if there have any images it will be update this image portion with the images and also else it will be updated okay it should be updated another one that is else it will be updated only that brand name perfect so that's all that's all we have to do now let's check this out okay now let's check this out if you click the save all now go back click as a brand again so now i want to do one to updated that image now click the edit i only want to update this name i don't want to update that image okay now click the update image that means update brand yes you can see it's not successfully updated that means our text is updated if you go to our brand yeah our text brand name is updated so now i want to do i don't want to update it that brand name i only want to update that brand image now click the edit so now choose that image i want to choose this one right now okay or this one click as you open and now click the update brand yes you can see it's now successfully updated our brand name is the same but our image is updated if you go to our brand yeah you can see there is our test and there is our brand image is updated and if you go to our folder you can see that exactly the three pictures so always it's replaced with the new images okay so friend i hope you enjoyed very much so every functionality which is very much essential i share everything with you so if you actually practice it that is the main core functional difference so if you actually understand this main core functionality you can create any dynamic website as per your demand okay friend so here we successfully complete our update portion we successfully complete that edit portions right now you can edit it and also you can update it so in our next video i want to discuss about the delete portion then our this code application will be successfully done so here we read it we can insert this data we can edit and also can also update it so we can delete this data in our next video i will show you that things with a live example so thanks for watching and i'll see you in the next video
Info
Channel: Kazi Ariyan
Views: 339
Rating: undefined out of 5
Keywords: laravel 8 crud step by step, laravel 8 crud, laravel 8 project, laravel 8 tutorial, laravel 8 Fundamentals, laravel 8 laravel, laravel tutorial for beginners step by step, laravel project, laravel advanced tutorial, laravel beginner tutorial, laravel crud, laravel crud operation tutorial, laravel complete tutorial, laravel database tutorial, laravel framework, php frameworksphp, laravel registration, laravel basic, laravel for beginners step by step
Id: wLRhk9jc9y0
Channel Id: undefined
Length: 17min 53sec (1073 seconds)
Published: Thu Apr 22 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.