#39 Create Contact Form | Laravel 9 Essentials | Laravel 9 Tutorial

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello friends welcome in this video i'm going to create a contact form for our project so in the previous video we learned how we can send mail if i open the vs code here we get road cat in the webroads road get contact and we sent the mail in this video i'm going to create a controller and here in the road get i'm going to show the form and also we need to create another method for sending the mail okay so let's create that controller first i'm going to open here the terminal and say php artisan make controller and let's name it a contact controller hit enter okay and in the web road i'm going to comment this and let's create another route so let's say road get slash contact or slash contact and here i'm going to use that contact controller and the method is going to be show because i'm going to show the form here and let's name it contact dot show and we need another road to post the form and send the mail so let's copy this duplicate and say say road post now we need post contact the method is going to be submit or rename it submit you can name it what you want and i'm going to name here contact dot submit let's save it let's go in the contact controller and create the show and submit method so function show and here we need this to show the form so i'm going to say return the view i'm going to create a new view inside the contacts and i'm going to name it show okay also let's create the method submit so function submit and here we need the request but let's uh leave it for now as it is because i'm going to create a separate request for this contact form okay first let's go and create this contact go blade so inside the views resources views let's create a new folder and i'm going to name it contacts and here i'm going to create a new file name it show dot blade dot php now here i'm going to add the x glass layout okay let's add a div with class max with the b7 xl mx auto and also i'm going to say margin top to eight and here we need to add the four so i'm going to say form with method the b post now the action is going to action is going to go to the road we created earlier so i wrote contacts submit let's close this and let's add also here the csrf token and we need the for contact i'm going to add this form i have prepared name emailing message so let's copy this and paste it here if i save and let's navigate now inside the slash contact and yeah here it is our form now uh i want to add in the input i'm going to tape input here is for name input and without the name to be name and here the name to be email and the next one here is going to be message content the name is going to be content let's save it here i'm going to create as a set a separator request so let's open the terminal and say php artisan make request and i'm going to name it contact request and because we are in the terminal let's create also the mail so php artisan make mail and i'm going to name it contact mail and i'm going to say dash dash and create a markdown mail so mark down and here i'm going to say inside the emails i want to create a contact mail hit enter mark down okay and if i open now inside the mail we have this contact mail good inside the resources views we have the mails and we have this contactblade.php which has a component this is the markdown mail okay first let's open the request we have created so contact request change the authorized to be true and what what we need to authorize the validate here we need the name which is going to be required we need the email is going to be required as well and also is going to be email and the content let's say here content and here at required okay let's save it close this one let's go in the contact controller and add that contact request here dollar sign request okay now we have validation here in our form and here we need to send the mail but send the mail here we need the name email and message so let's open the mail contact mail and here in the construct i'm going to say public string dollar sign name we are going to accept the name to expect the name the email and the content so let's say also public string dollar sign email and public string dollar sign contact okay now here we return the markdown this uh emails contact blade and because we added the name email and content in the contact blade here and with the same in the introduction i'm going to say a contact from and display the name because we have access to the name because we expect here and make this public here is going to be the content so let's say dollar sign content oh sorry in double curly braces dollar sign content now if you want to add the url a button here okay thanks from the name config app name so what we have in the dot dnv file i name it essential and here is going to be essential thanks and an essential and let's say i want to add a button here to say visit us and let's add the url or url which is this url let's copy here and paste it okay if i save now this is not going to work because is uh not going to need to be intended and but let's leave for now now in the content mail contact mail sorry here i'm going to say instead of just rendering this contact blade i want to say mail the last dollar sign this and i'm going to add a subject okay and here i'm going to say contact from dot essential.com or dot test okay and i'm going to say reply to the email we have here so don't assign this email and now add the markdown okay let's save it now we have done the contact mail also the contact blade in the contact controller now when we say submit here i'm going to say mail the same thing we have done in the previous video so mail today s1 and send and give it the mail so let's say mail and we need to import that so mail import the facade so the my mail so let's say just my mail.com because it's going to come out of my mail and now let's say send new and contact mail and here now we need to add the name email and the content okay and the name in email and content is going to come from the request so let's say dollar sign request name dollar sign request email and also dollar sign request content okay after that i'm going to return to the road welcome i'm going to return to the welcome page if i save and let's go and try so in the contact refresh first in the mydrab.io i don't have any mail right now so it's empty let's say admin email is going to be admin admin.com and let's say first contact from essential dot test let's say submit okay and we redirect to the essential.test if i come here we have an email contact from essential.test which is the subject we added okay contact from essential.test here is the subject and here we have the essential which is the app name we have in the dot env file here we have contact from admin we added in there so if i go in the emails contact blade contact from the name the contact from admin we added the name ad admin and here is the name and here we say first contact from essential.test this is the table because we don't we indented this the vs code intended and we don't need to indent that and here we have visit us which is this button here and it's going to return us to the essential.text so if i click here yeah it's going to send us to the essential test okay friends that's it how we can make a contact form in laravel so let's say name john doe email is going to be john.com and message from [Music] john doe click submit again it's going to take some time and if i come here we have a contact from essential and here is contact from john doe and message from john doe okay okay friends i hope you understand if you like a content like this please subscribe to my channel like the video and see you in the next one friends all the best thank you very much
Info
Channel: Code With Tony
Views: 7,937
Rating: undefined out of 5
Keywords: laravel, vuejs, livewire, laravel 8, laravel 9, laravel crud, laravel 8 tutorial, laravel 9 tutorial, laravel 9 new features, laravel essentials, laravel 9 essentials, laravel for beginners, laravel 9 tutorial for beginners, full laravel course, laravel project tutorial, laravel tools, laravel 9 setup, laravel 8 tutorial for beginners, laravel tutorial, Laravel project, install laravel, install laravel on mac, install laravel 9, routes and layouts, laravel blade components
Id: Y-iNNti_rRg
Channel Id: undefined
Length: 16min 30sec (990 seconds)
Published: Wed Jun 08 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.