hey what's going on guys welcome back to our blog and welcome to this particular blog so this is actually the part 12 of our laravel tutorial for beginner series and in the previous blog we have laid out the basic structure of our form to enable us to submit data using our form into our database so in this blog we're going to continue working on with this form and let's try to add some template for our messages inside our create page so let's go to our views and let's create another directory here so this should be in a NC and then this we will create a new file here called messages that laid that PHP and then we're going to include this file into our app that laid that PHP so we're just going to configure first this messages that laid that page wait for now and first let's just check if the count for errors is greater than zero so let's just close first the if statement and we're going to define a for each here and let's just close the for each below and inside this for each as we're going to iterate the errors and this is an object so all and then as error and of course we're going to define a very basic alert to our user by using the bootstrap alert elements so this should have a class alert and of course because this is an error so it should be danger right and of course the error itself display and also we're going to check for messages for session coming from our page so session and then if it has a success value so we're just going to end the end if here so just bear with me guys because I'm just going I'm just laying out the messages or the feedback to our user if they have something or if there's if there were errors during the process of submitting the information so div and then of course it should have the alert also alert success and the value of our session and success and then we're just going to do the same for our error coming from the session so this should be error also and instead of success it should be danger and also here is the error okay so we need to include this inside our layout up that laid out by HP so I think somewhere before the main container okay or after the container element so we're just going to include the messages here so add and then include and of course the directory and the template messages so save this one and try to let's try to preview it in our page so refresh and then submit so there you go we can see the title field is required and also the body field is required and try to populate the title and then only the body field is required because we don't have the because we did not populate the body of our post so now let's go back to our post controller and continue working with our store function so you remember that we use tinker before to populate our database so we can actually use that also in here so post and then equal and the new post and we can use that instance for now so post and then set the title for our post which has the request or the value coming from a request and technically it is the value coming from the forum so we we should specify the input which has the title and then of course we can actually get the value of our body the same thing as the titles or requests and then the input and of course the body and save this supposed and then save then we can read the req to another page or to the post page so returned in the redirect to the post page and it should have additional information so with and then of course success so remember we have defined this in our messages that laid that PHP file and this is how you set the value of the message so post created and then something like that and try to save this and let's go back to our browser and try to preview it so refresh and then let's try third post because technically this is the third post so post three and then this is the body D post number three and then submit so it is now redirected to the post page and it has a feedback post created so the alert message that we have created in our messages that made that PHP so now we have three records in our database post one post two and post E and then if you try to click any of this post we can redirect to another page with all the information included or displayed in this post and now I wanted to add a link to create a post because for now we don't have any link here that says we can create a post so let's go back to our app that laid that PHP file and then we can see here all the links from our navigation the home services blog and about and this is the right side of our navigation so I think we can just copy this now item here and then paste it on this left side of our navigation so this is create post or we can just say add post post and then it should be direct in to post create so let's try this so save and then let's go back to our browser and refresh so as you can see we now have the add post link here and it should redirect us to deform once we click it so we a working link to add post now and I think it's high time for me to add a sin tax highlighter for now for the blade templating because as you can see we have all the syntax here or all the scripts for our blade templates here but we don't have a syntax highlighter for that all we see is a white tax and then I think it's not readable for us so let's go to file and then settings and then packages and then let's try to install or try to go here in in install and search the package language and played so language blade so it is a syntax highlighter for the blade templating engine used in laravel so we're just going to install this so it should enable us to read the syntax of our blade or syntax of the blade much easily so let's try this and then let's just wait for a few seconds to allow the installation to complete and I think it's it is now complete let's go back to our file and as you can see we do have now the syntax highlighter or syntax highlighting for rate templates and it it will be only activated on files that has blade that PHP file extensions so I think that's all there is to it for this tutorial and I hope you have learned something from this blog and in the next blog we're going to discuss how to edit and update our records by using our laravel project so thank you and see you in the next blog
hey what's going on guys welcome back to our blog and welcome to this particular blog so this is actually the part 12 of our laravel tutorial for beginner series and in the previous blog we have laid out the basic structure of our form to enable us to submit data using our form into our database so in this blog we're going to continue working on with this form and let's try to add some template for our messages inside our create page so let's go to our views and let's create another directory here so this should be in a NC and then this we will create a new file here called messages that laid that PHP and then we're going to include this file into our app that laid that PHP so we're just going to configure first this messages that laid that page wait for now and first let's just check if the count for errors is greater than zero so let's just close first the if statement and we're going to define a for each here and let's just close the for each below and inside this for each as we're going to iterate the errors and this is an object so all and then as error and of course we're going to define a very basic alert to our user by using the bootstrap alert elements so this should have a class alert and of course because this is an error so it should be danger right and of course the error itself display and also we're going to check for messages for session coming from our page so session and then if it has a success value so we're just going to end the end if here so just bear with me guys because I'm just going I'm just laying out the messages or the feedback to our user if they have something or if there's if there were errors during the process of submitting the information so div and then of course it should have the alert also alert success and the value of our session and success and then we're just going to do the same for our error coming from the session so this should be error also and instead of success it should be danger and also here is the error okay so we need to include this inside our layout up that laid out by HP so I think somewhere before the main container okay or after the container element so we're just going to include the messages here so add and then include and of course the directory and the template messages so save this one and try to let's try to preview it in our page so refresh and then submit so there you go we can see the title field is required and also the body field is required and try to populate the title and then only the body field is required because we don't have the because we did not populate the body of our post so now let's go back to our post controller and continue working with our store function so you remember that we use tinker before to populate our database so we can actually use that also in here so post and then equal and the new post and we can use that instance for now so post and then set the title for our post which has the request or the value coming from a request and technically it is the value coming from the forum so we we should specify the input which has the title and then of course we can actually get the value of our body the same thing as the titles or requests and then the input and of course the body and save this supposed and then save then we can read the req to another page or to the post page so returned in the redirect to the post page and it should have additional information so with and then of course success so remember we have defined this in our messages that laid that PHP file and this is how you set the value of the message so post created and then something like that and try to save this and let's go back to our browser and try to preview it so refresh and then let's try third post because technically this is the third post so post three and then this is the body D post number three and then submit so it is now redirected to the post page and it has a feedback post created so the alert message that we have created in our messages that made that PHP so now we have three records in our database post one post two and post E and then if you try to click any of this post we can redirect to another page with all the information included or displayed in this post and now I wanted to add a link to create a post because for now we don't have any link here that says we can create a post so let's go back to our app that laid that PHP file and then we can see here all the links from our navigation the home services blog and about and this is the right side of our navigation so I think we can just copy this now item here and then paste it on this left side of our navigation so this is create post or we can just say add post post and then it should be direct in to post create so let's try this so save and then let's go back to our browser and refresh so as you can see we now have the add post link here and it should redirect us to deform once we click it so we a working link to add post now and I think it's high time for me to add a sin tax highlighter for now for the blade templating because as you can see we have all the syntax here or all the scripts for our blade templates here but we don't have a syntax highlighter for that all we see is a white tax and then I think it's not readable for us so let's go to file and then settings and then packages and then let's try to install or try to go here in in install and search the package language and played so language blade so it is a syntax highlighter for the blade templating engine used in laravel so we're just going to install this so it should enable us to read the syntax of our blade or syntax of the blade much easily so let's try this and then let's just wait for a few seconds to allow the installation to complete and I think it's it is now complete let's go back to our file and as you can see we do have now the syntax highlighter or syntax highlighting for rate templates and it it will be only activated on files that has blade that PHP file extensions so I think that's all there is to it for this tutorial and I hope you have learned something from this blog and in the next blog we're going to discuss how to edit and update our records by using our laravel project so thank you and see you in the next blog
Post a Comment