hello everyone welcome to this carbon calm here in this video I am going to tell you how to implement search functionality with paginated data in the previous video I said how to implement search functionality in here we also implement search functionality with the page rated data this is the posture you can switch is also working demo here you can test it this how it works there are thousands of records here we can search further samsara will search for like this and you can see these are all the names related to surah here this is Sara this is one more and is the search also paginated here so these are we can search if we can search for our you'll have lots of results you can see 170 you have page a at up to 170 so that's how we can implement this search functionality with paginated data so we are going to implement that now so let's open my terminal create a new project I will go to workspace and I'm going to create a new label project using this composite create profit command composer create project laravel are well and I'm going to give the app name as pagination search video and I'm also going to safer the version as 5.5 so it's creating a new liable project for us so our application is set successfully so now we'll go and open this project in our sublime text editor so so this is our project so first we'll go and remove all this from this in this welcome dot dot PHP will remove all this and we'll just need a form like a search form and a table to display the results you can see here in this more we just need this search form and the table for displaying this details so let us first create this HTML markup so I have pasted this basic form here this has one input field that is a search field this is input type text this is a placeholder for search is seen and we have group a button to it that is a search button as you can see here this is a button this is the field search users and this is the button group date so if we refresh this ends here you can see the search users and this search button so nothing has happened also we need to create this root now slash search so we'll go to roots dot roots and we'll open this Web dot PHP file will create a root here we can also use get and post so that we can write any here and that would be slash search there is only one function in this simple example so I will create it here itself instead of creating a new controller and all so now we will get the Sun will get that variables using this input function input there will be get get and that would be Q the variable name is I mean the text field name is Q here so you will get the value here like this and for that we also need to import this here you can import it like this so now if I go here and refresh it so if and some w/e it should return w he here so that we can confirm that it is coming here and one more thing here is instead of returning this instead of just returning this welcome here we also need to create a table and create some data here as you see in the example here by default will have some data if you go and search by default they will have a thousand rows of data with pagination so we will get this table and some dummy data so first we'll create the table for it so below this so below this container will create another container and in that container we'll keep the table here so this is a boil plate of the table here we'll just have a head that will say name and email and we will have this body with the name and email here we'll get this from the database here so we will query the database here and we'll chop so we'll come to database here go MySQL – you wrote and – B I'll enter the password I will use this table called just larval database change now I will create a new table here actually we have table I think Shore tables you can see dummy details I have already imported the dummy data here dummy details we can also see all the data here select you can see thousand rows we have thousand rows of data with this email and name all this all the data so I will use this table here so for that we need to create a model here in our larval application so if you go into our application and see in the root and the app folder you can see this dummy details for PHP resistant model so what can do is we can show a creative variable here that is that protected that would be a table and we'll use a table name here that table name will be dummy details as shown so so in this step dot PHP will get the data from those model here so we need to use it use it app / or dummy details in here we can use that dummy del store or you can say data equal to this so this is the mediator all we can use this all and we can also paginate this data we can just paginate it we can paint it by 25 element 25 record speech so we will get only 25 cards or each time and I will pass it to this data here with data and I will pass this variable data here so now we will go into the view here and here we'll do a 4-h 4-h we say $1 data as user something like that and we'll enter it sure and it's a user of user email and name those fields are say user of name and here we will just show the email here actually we forget one thing we need to is a database details in dotty and Wi-Fi and quickly place them there in this place we will need to place this database name is just larval username is root password is also root so now we need to four also we will stop this and run this again so now if we refresh this page you can see this is all the details this is all we have these all the details as you see we have got 25 adults but there is no page nation link here actually there are thousand records in the database but we have seen own identified records as we as I said here to page 8 by 25 and in this page we did not render the pagination so we will render the page nation here so that we can see only 25 cards so after this table I will use this we can use this thing here like this and we can call them render function here on users users Renda so it should be data not users data of Brenda and now let's refresh this you can see there's page nation here up to 40 records there are 25 in each page and thousand records there is 40 records and now we will implement this for search functionality no so in this lab dot PHP we are getting this here we'll just remove this comment and we'll use dollar q equal to that is QV equal to input dot get view so we'll get this variable so now we will perform a database search functionality now so if dollar Q naught equal to empty we'll check for whether that is a empty or not if they know if that is not empty we will proceed further I will use variable equal to that is the database name is Tammy details tell me details we'll use this where where name and we'll use this like operator and M like this we can use this percentages so that and this name would be like this dollar Q here that is the other thing we are searching for and again we can give this a person register this so we can search for a particular piece of a thing instead of the whole thing you pay search for like so if that particular mentioned word or a particular string is anywhere in this particular name it will show us for it will show for us that's how it can search within this a percentage and you can also do one more thing we also search in nit for Emer also same thing we will search for email so whether we enter the search thing search query is in name field or an email field will search it and here for search result will page 8 by 5 and we are using custom page nation like thing we will also use this set path thing we will set it to initial like this but all that is else would be stored in this user variable here the set path we set it as empty because I'll just show you here this is a form when we serve something like saara here it shows the result now so now you click this to here you can see slice u equal to R and P is equal to 2 but if you give some custom URL here like some something like this so what happens here is yeah instead of this it would have come like /sf something like this so we don't need that so I just kept that path as empty so that's why I kept the path as empty there so we'll just use this path is empty so now I'm asserting this we need to open this user links so we are searching we are getting some results and in that search results we are paginating so we need to append something here to the users so dollar users we type in the query here there's a function called happens here and it takes array as a parameter array and item would be Q here and it will take its value as value which are getting from the input input get Q so this would be the variable here so we append to those results so for this so what happens now here is we will search for this name like dbl Celsius and we also we are also page knitting here so so first result will only see the 5 year if they have more than fire results we need to paginate them for that position to work with this results query we need to do something like this we need to append this same this variable same we need to append this here to this user syrup sorry not users this is user so we need to append this to the users array so finally we will get all the details when this users variable so and one more thing I am going to change this variable as data itself because we are rendering because we are rendering here this wearable data or render so we need to give business on this data variable itself so I have given that so now we'll check if count of this data dollar data is greater than zero then we can only be able to show the results a greater than zero we'll just return with written in view with welcome return you will copy this enough so we'll return without command this fateful data and this data so there are no results well turn you will return you with message some maid will say G and we'll type the message as no results found and we'll use this message variable in our here in this welcome dot dot PHP so before this table we'll use this he said command so he said there are only this data if we said only data is there we'll perform this make this if is it so if data is there we'll perform all this and if that is not there we'll do else and we'll print that message here so we don't need this here we will print that message here but that is taller than me this is G so that's how it works then we'd also need to end if it so what happens if we sit there dummy means from here we are sending data of count to greater than zero by sending this data where else if the dad is whatever else and we are not sending any data so now we'll check it so now let's just it giving some to a and clicking enter you can see these are the results and if I click this to here you can see this there are second page results are here so that's it for the video guys we have implemented search functionality we haven't printed the pagination functionality and we have combined them both in the initial generated the data with 25 all the thousand records and then in stock then we are searching with those in search results we have paginated it to 5 and it is also you can also search like this it will come the next page results Judy Hill iron Oliver and Anderson and the first way to get the first phase results there is how we can implement pagination and search functionality in our world and I want to just tell you all the quarries are below on github here so this is a project here this is my username ammunition and it's a repository name page nation in search bar one so you can use this git repo if you liked this video please subscribe the channel that means a lot to me he'll be differents cuter like comment stay tuned for more videos from the server load come see you in the next video bye bye thank you for watching now it's time to discover more simply click on the screen to subscribe to our channel watch another video and visit our webpage you

How to implement Paginated data with Search functionality in Laravel

7 thoughts on “How to implement Paginated data with Search functionality in Laravel

Leave a Reply

Your email address will not be published. Required fields are marked *