32 Pagination and Flash Message - Laravel 11 tutorial for beginners.

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
Hello friends Tony here welcome uh in this video I'm going to work with pagination right now we have some posts here and I want to display only uh six post per page and also when we create a new Post Yeah we send the email that the post is created but we redirect uh post index page and we need to scroll and see where the post is so I'm going to display a flash message saying that the post is created successfully okay so let's start and work with that let's let's open the vs code and the first thing I'm going to open the post controller okay here on the index method we saying post all but instead of that we can use the pinate method and here we need to specify the number how many post we need to display so in my case I'm going to say six and right now if I save just by adding that and come here as you can see we have some post here all the post but if I ref fresh now we have only six of them good now we need some uh links here pagination to click to navigate the second page and so on and how we can do that let's come here and on the post index page so let's open the index inside the post we make a for each and let me just close like this we make a for each after the 4 each I'm going to add the div and let's add the class to be margin top of six and inside this I'm going to add Double C braces dollar sign post variable and because now we use this pagination pinate method we have also a links method aailable so we can chain the POS the links method and if I save just by saying that thing come here and yeah we have have previous and next refresh click on next we navigate the next page next page as you can see page number three previous and previous also if you want more you can go to TWI config.js and here you can add this so vend framework Source illuminate pation resources views plate okay save that and then you need to run the mpm r Dev of course and with that now we have this nice uh vagination okay so we we can click directly the page number three page number one and so on good that is the pagination so very easy with laravel now let's display a flash message when we create a new post okay and for that we need again to go to post controller and let's scroll down when we store a new post we create the post here we dispatch a job and then we return to the outout post index when we return there I'm going to say return with a message or status or what you like so this is the key the first one is a key and then the value the key I'm going to name it a message that is going to be stored on the session and the second is going to be the value so the message which I'm going to say uh post created successfully okay like this with that now we need to display that because right now if we create that it's not going to be displayed we need to display on the post index we return to the route post index let's go to the index and here I'm going to render the message for that I'm going to use the flow bite this success alert and let me just copy that here we have let's copy and paste it here right now if I save and just let's see this go to post index page yeah this is the alert I'm going to say also here to be margin bottom four and margin top of six come here yeah we have six okay then uh instead of displaying always because if I refresh yeah this is going to be displayed I'm going to display only when we create a new post so for that I'm going to cut this and put in the if statement so say if and use a session we have a helper session method and here we need to specify the key when we added here message so if you have add something else pass that so let's say message if the session has message I'm going to display this and now in the success alert instead of the hardcoded I'm going to say double col Braes again use the session helper method pass the key which is in my case message and this one I'm going to remove okay so we say if the session has a message display this div and pass in the session message here go to refresh as you can see we don't see now without but let's go and create a new post use fake Fielder choose image here and sa store we are redirected back and now we have this post created successfully very good let's do the same thing also on the update so what I'm going to do I'm going to copy this and scroll down when we up date return to the route post show and here also we're going to do the same thing return with the message now here I'm going to say post uh post updated successfully okay save now we need to go to post show page and do the same thing we have done here and you can do that but instead of this I'm going to cut this and move this Logic on the layout so let's open the layout and here so the na bar I'm going to P this session if check session okay good now let's create a new post and see so this with to say arogant post just to see this belong to this user store post created successfully yeah we have the flash message and just let's see now where the post isrow can post is here click here and we don't see the edit and delete button and we don't see that because we need to go to post policy because here when we add this before I changed the return to false this mean only the admin can uh edit and and delete post here we say we have a bullion or null if we return null here and I do that just to show you if we return null and refresh now we have the edit and delete and this is only for the arogan Post okay so if I click here we don't see the edit and delete okay let's go to edit and let's say updated if we say updated choose update we redirect back to post show page and we have now post updated successfully okay friends that's it all about this video what I wanted to show you the pagination and the Flash messages now if you like such a videos don't forget to subscribe to my channel like the video share with your friends and see you in the next one all the best thank you very much
Info
Channel: Code With Tony
Views: 786
Rating: undefined out of 5
Keywords: laravel, vuejs, livewire, laravel 8, laravel 9, laravel crud, laravel 8 tutorial, laravel 9 tutorial, laravel 10, laravel filament, laravel components, laravel layout, laravel 11, laravel 11 for brginners, laravel tutorial 2024, best, 2024, tutorial, laravel 2024, laravel herd, laravel reverb, validation, forms, laravel 11 crud, admin, admin area, send emails, file upload
Id: e6NXiVs3Irw
Channel Id: undefined
Length: 8min 30sec (510 seconds)
Published: Mon Apr 29 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.