"R" - Read | Class & Search Method | Laravel Livewire CRUD

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hi everyone clash of walla doing well so we finished up with the creating the tag now what we're going to do is we're going to display all the tags and what we're going to do is we're going to search a tag all right right here and we can obviously order them so let me just do this we can order them by the name by the id so let's say the name we can order them ascending or we can do a descending and we can do obviously the created add date and we can display a harmony per page so that's what we were building in this episode another question i just want to post to you right up front right here let me know if you guys want this to be in separate views so as you can see we got the create view around here we got the index view so all on the same view underneath each other right that can be option or i can do a tags like this is the index view and then i can have a create view and then i can have a show view all that kind of stuff so i can put them all in separate views please let me know and i will see you guys in the comment section but anyway let's quickly start building this up right so the first thing we're going to do is we're going to create our index view so open up your terminal so php artisan make and we're going to make a love wire component and we're going to do that inside the tags folder and we're going to call that one index all right so as you can see we've got a class in a view created for us all right so let's go to the class under app acp live wire tags you will see we got our controller right here so are basically our live file component now the first thing we're going to do is we're going to use page donations we're going to say use with pagination just make sure you bring that in import that at the top as you can see it brings it in right there the second thing we're going to do is we're going to create a public variable called per page and we're going to set that to 10. the next one is we're going to create a public variable and we're going to call this one search this is for the search functionality and we're going to set that to an empty string for now okay the next one is we're going to create a public variable and we're going to call this one order by and we're going to say that by default to use the id okay and the other one is we're going to do a public uh order ascending asc asc and we're gonna set it by default to true like this all right now the next thing we need to do is we need to be able to render that tag okay so let's just quickly do this all right so what are we going to do is we're going to pass all the tags to this view right so we need to get the tag so we're just going to do tag and we're going to create a static method inside basically our tag component called search basically our tag model called search and when we pass through we want to pass this search indeed search right so we want to pass that to the component and what we want to do is we want to order that by so order by and then we just want to say this order by so basically the method that we created there is of the public property actually and we want to save this ascending we want to check if we call on this method so order ascending if it's true use asc else use dsc okay and what we're going to do is we're going to paginate we're going to paginate with the amount that we set it right here so by default i set it to 10 okay so we're just going to do per page so just actually we need to reference as this this page like that okay so now what we're going to do is we're going to get all the text we're going to create that method in a second then we're going to check we're going to pause in the search we're going to check if the order by by default right this order by is the id so if we change that to be the name it will search it by that name and we're going to order by by default it's set to true so we're going to do order by ascending so if this is true set it by ascending if it's false just set it descending and we just want to paginate it this per page all right so let's quickly open our tag model and actually create the search method all right so just do like this tag model right let me just give it some room here so like this let's open up tech model quickly right in our tag model around here we're going to hit public static functions static function and we're going to call this one search and we're going to pass in that search variable like this right so what we're going to do if the search is empty all right so in this case let's say by default we set it as an empty string okay so what we're going to do if that search is empty so we can just going to put empty and we pause in the search variable okay so if it's empty just do aesthetic quit query okay so we're just going to do a static and then we're just going to do query all right else all right let's put the else in here let's put it underneath each other it will be better to read it actually so if the if the search is empty do this else we're gonna basically do the static query aesthetic remove this i'm going to do the query all right so we're going to do that we're going to check where in this case we're going to check the id where the id is like percent mp okay ampersand and then we can just concatenate the search and then we can concatenate the ampersamp again all right so meaning what this is is it actually got a whole lot of different fields let's say you're doing it for the post now in this case we're going to check if the id is equal to the search result basically right there so if we type in one we're going to check if the tag is equal to that the next thing we're going to do is we're going to check all where i'm thinking of water or where the name [Music] is like i'm gonna check the ampersand now we can concatenate the search like this right so now what we're checking is we're checking whether id is like the search or where the name is like the search if you let's say we're doing like a post like i said before you can add a couple of always statements right here so let's say you've got a title you can add the title in there or the body like this and then you can just obviously end it off with a semicolon right here okay but we're not going to make use of that so i'm just going to delete this so just for if you guys want to do that for a post or whatever the case might be right so we can check the query right if this is empty by default we sent an empty string like that okay so it will be empty so it will just basically return nothing all right and if it's not empty we're going to check where the id is like that search that we pass through or where the name is equal to that search and if you have extra other fields in your database that you want to check you can do them like here or with always statements all right that's it right so what we're going to do in the next episode we want to actually work on the table right there so all the tags that we're going to get we're going to work on them and basically loop over them search them and all that kind of stuff in the next episode but like i said let me know if you guys want to see all of this in one view or in different views right thank you guys for watching like the video if you like it questions feedback suggestions in the comment section thank you guys see you in the next one adios
Info
Channel: AngelJay Academy
Views: 252
Rating: undefined out of 5
Keywords:
Id: 5jbv0Zqi4N8
Channel Id: undefined
Length: 9min 0sec (540 seconds)
Published: Mon Nov 15 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.