Planning & Kickstarting the Laravel Application

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] um [Music] [Music] [Music] [Music] um [Music] [Music] so [Music] hello everyone and welcome to today's stream hopefully today everything will work great i work it quite a lot since yesterday and today on making sure the audio and the video and the signal is okay i don't have control over the internet connection i'm afraid but let's hope for the best usually the internet here is good but yesterday it was i was not lucky so hopefully today everything will go great so what this stream is about as you may know i last for the last two months i started creating content for the laravel youtube channel and each time i want to showcase a feature i had to build the laravel application just to showcase this feature and this was talking a lot of time taking a lot of time and it was slowing me down so i thought why not just build a laravel application that has most of the ports ready and touches a lot of areas around laravel components and laravel packages so whenever i need to showcase a feature or showcase how to upgrade a laravel application or a laravel package from release to another i can just fall back to using this application and this will save me a lot of time and then i decided if i'm going to build the laravel application why not do it live so people can see my personal process and my preferences on building a larval application from scratch based on my experience building laravel application for the past seven or eight years i don't really remember for those of you who don't know me my name is muhammad saeed and i'm i'm a web developer at laravel since 2016. i work it on the core of a framework as well as multiple other first party packages that laravel offer hello from lebanon hello there hello from nepal hi there sounds fine today everything looks okay hello from afghanistan hi everyone so i think today is going to be great let's hope so so for those of you who didn't uh who weren't there at the stream yesterday i'm go i'm gonna give you a brief of what the idea of the application is all about i'm building an application that is air pnp but for renting offices for remote workers not co-working spaces but offices like a room i don't like this room that i am streaming from you you move to a place a new place with your family and you want to find a quiet place with good internet connection and ergonomic desk and ergonomic chair where you can just put your macbook or your device and start working on whatever you your drop is or if you're traveling on a vacation and you need to rent an office space that's prepared for remote work uh not a hotel room not a co-working space just a private office space like this one you want to rent it for a few days during your family vacation so you can continue working if you want of course like on vacations i don't really work but if you want and if you have something that really important that you want to focus on during the vacation you can have the sauce so this is the application we are going to build and uh the thing about this application is that it can be extended we can uh uh while renting an office space you can we can offer renting others other things like i want to rent a monitor i want to rent some keyboard and some mouse whatever we can add we can have an online shop so we can touch e-commerce in laravel we can have a subscription service and we will be using cashier and spark we can leave review we can let people leave reviews on the offices and use different eloquent relationships in the process which will be a good way to showcase the features of eloquent also we can use redis for analytics given that if the or we assume that this airbnb like project is going to grow and we need to collect analytics from different sources we can use redis to put those anal analytics in regis so it's easier for us and faster for us to find whatever is going on with our application while we just take a quick look and finally we can work on generating some heavy reports which will allow us to deal with big data and allow us to deal or do some complex cued workflows using patches and using chains so the idea can really be extended to do whatever we want of course like the basic things like registration email verification logins broadcasting queues password resets all this stuff will be covered also we are going to build the application as an api first we are not going to touch the front end now we are only going to build the back end and we will prepare this back end to deal with whatever front end that will be dealing with it in the future we will prepare it for an spa front end for a blade front end and for a mobile application so we will touch session paste authentication and we will touch token based authentication we will also touch user authorization and we will touch token authorization so i've been thinking about this idea for quite some time until i found something that can't be extended to touch all the areas that i think are useful for you guys to know so let me share with my screen to get started i'll take a quick look on the chat hello from ukraine from pakistan hi everyone greetings from sudan hello everyone uh yes i'm gonna put this uh the videos in the playlist all right what do you think about repository and service pattern we'll discuss that all right uh hi from argentina all right so everything is great let's get started on my today is to to-do list we want to prepare the migrations for the application we want to see the initial tags i'm going to explain this in a second and we're going to prepare the models prepare the factories prepare the resources for the api responses and we are going to work on the tags hopefully the routes the controllers and provide some tests and we will start working on the offices resource specifically the less office's endpoint and the lead office rent point and hopefully if there is time if there is enough time we will start creating offices in the system and see that process my plan is to stream for 45 minutes to one hour so let's see how it goes previously in the stream for yesterday we created the resources needed so we have the models for the image office reservation tag and user and we also have the databases created or the migrations created so here we have the tags table each tag have just the name and we have the offices table and office each office belongs to a user and the user that's the host of the office and it has a title description location address approval status and uh if whether it's hidden or not price per month and monthly discount i explained this yesterday but uh i think the stream wasn't good enough and people joining us today so i'm gonna touch it uh touch up around all these attributes just in a bit so i'm just showing you the kind of database that we are going to deal with and offices can be attached to tags so here is a table that links an office with a specific tag so tags can be something like has private bathroom has a refrigerator has a coffee machine and things like that so we are going to see those tags in the database users won't be able to create tags or manage tags we will put these tags in the database and uh hosts can attach tags to their offices how they see fit they cannot add tags that are not already existing in the system and there is also the images staple which will it's it's a polymorphic relationship that holds a relationship between an office and images each office can have multiple images and why we are using a polymorphic relationship is a morph many relationship is because we want to attach images to other resources not only the offices so we maybe attach images to reviews when people leave a review they can put images we can attach images to products if you ever have an open or an online e-commerce shop for this application we can use the image resource to attach it to the product resource as well and finally here we have the reservations table it holds the user id that the reservation belongs to the office id the current price when or the price when the reservation was made and the status of the reservation started of the reservation end date and the time stamps and for the tax table we don't have the time stamps we don't need to know when the tag was created or updated because those tags are gonna be managed by us and for the offices we are using soft delete so the office resource will not be deleted from the system ever it will stay unless we find uh in the future that we we need to delete so that's basically the schema that we are going to deal with i've also created the factories of line just to speed things up so this is a factory for the image each ms have a path and then where we will discuss uh using or uploading images to a desk and we will look into uploading images maybe to that an s3 pocket but for now we'll just uh each mf image has a path that's it that's all about an image and for the office factory uh we link it to a user title description and yeah regarding the title there is something that a problem that i i hit while building this if you use the words helper here and you provide the number of words this is going to return an array not a string and while feeding the database or white seeding the database it's expected that this field is going to be a string not an array so if you are going to use the words helper method here faker method make sure that you provide the second argument as true so it was it will it will return it as a text or as a string not as an array by default it will return it and as an array and as an alternative you can use the sentence helper here which will provide a sentence for the title and we are faking the latitude longitude and an address we also have the approval status hardcoded to 2 to 2 which is basically approved and by default it's not hidden the price payer they it's a number between 1 000 cents and 2 000 cents and the uh yeah and the monthly discount is zero and for the reservation factory it links to a user and an office the price between ten thousand cents yep there's something wrong about this i guess and the status is one start date and end date i'm not sure why but phpstorm keeps i keep telling it that i am using php 8.0 but it keeps reverting to 7.3 i have no idea why so here's how we fix it let me take a quick look at the chat to see if there is anything i need to respond to so what is the morph in the migration so let's go to the migration here and for the images staple yeah the morphs this is just a shortcut it creates two so numeric moves it creates two columns so when you uh when you use the morphs method it will create a string column with the name of the morphable underscore id and another colon which is a pig integer with the name of the motor morphable underscore id and it will create an index as well so this is just a shortcut instead of having to create both columns inside the migration this will take care of it [Music] so let's see if there are any other questions will you use php stand lara stan for static analysis no for now we are not going to use it but after we finish the application we we may implement it and see what needs to be fixed but while building the application i'm not gonna use it yes phpstorm will take the lowest php version from composer to json interesting so composer to jason 7.3 so maybe just we leave it at 8 because that's what we are going to use thanks for the remark [Music] so i think we're good so we have the migrations and we have the factories let's try and run php arts and migrate fresh and see if we have success and here we go everything looks right if we go to [Music] sql pro we can see the migrations created successfully for us and everything looks great nice so now let's see the next step i have a to-do inside the application so we have the migrations ready and we need to see the initial tags so let's do that inside the tag migration here i'm gonna create some tags inside the migration so each time we run the migrations the tags will be created for us if we run it on a fresh environment the tags will be there if we refresh the database while while doing a uh while in local development the tags will be there because we need them so what we are going to do here is we are going to use the db facade and the table is the tags table and we are going to maybe we just use the model so let's use the model and create some tag and the tag has a name first tag let's have let's call it has ac it has air conditioning and the second tag has private bathroom spilling mistake and for the third tack let's see what i have prepared here as coffee machine oh all right so has coffee machine let's run the migrations and see if this works so let's run the migrations again oops we have the envelope property to allow mass assigned oh mass assignment the thing i hate most about eloquent is that mass assignment are enabled by default it this is a personal opinion it doesn't represent what the company thinks this is my personal opinion i personally don't like mass assignment protection because i never i never pass data from the request directly to the model i always i always validate the data and pass the validated attributes to the model i never pass the raw request so i'm gonna go to the app service provider and under the put method i think under model you can disable mass assignment or was it under builder mass assignment disabled model is it under model how to disable mass assignments so let's check some model chords attributes of course i think has attributes that's my way of finding as attributes so let's check has attributes origin so not here what was the guard's attributes so philippa guarded unguarded so that's the thing we want to set on guard yes so we are going to his model on guard and this should disable mass assignment protection on all models it will allow us to fill any attributes so let's go to the terminal and try again unknown column updated at yes because we need to go to the tag and be because in the migration if you remember in the tags migration you can see that we are not using timestamps so we are gonna call public timestamps and set them to false to disable them from the migration and here we go we have success if we go to a sql pro and check the tags and we can see the three tags created in the database and that's it yeah modern guard modern guard thank you for reminding me it's hard to remember all the methods and the entire framework so and instead of checking the documentation i actually look at the code it's something that i find faster than looking at the documentation because if you look at the documentation you need to read a lot of things before you find exactly the thing that you are looking for but if you read the code of course if you are familiar with the code already you can pinpoint exactly where the attribute or the method that you want to use is located and you can find how to use it that way so that's my preference for using for finding methods and attributes that i don't remember the name for so here we have the task number two done we have the initial tags it's time we prepare the models and to do that we are gonna open the migration here and the model here and see what we need to add to the model so for the tag model i don't think there is anything that needs to be added here maybe later when we link the tags to the offices we are going to have the relationship but for now we won't need it so let's move to the next migration file which is the offices and open the model for it and here for the office what we want to do is that first because this table soft has soft delete so we we need to use the soft delete straight and for an id user id so we have a relationship with the user so function user and this function will return that belongs to type so return this belongs to user class so that's the relation title description lot and latitude and longitude nothing to do here so maybe yeah maybe we need to add some casts so public casts and for the lot i don't know what the name of the cast should be numeric or is it decimal for the lat and long let me know guys what do you think and then we have the address approval status it's an integer so approval status and an integer and hidden is a boolean so hidden is a boolean decimal so we have we can use a decimal casting here thank you add motion lip decimal and abdul kodus and sulaiman khan thank you guys for the help so it's decimal price per day should be an integer so price per day is an integer and monthly discount is also an integer and i think that's it we don't need to maybe yeah has many reservations yes so reservations and this one will have has many return this has many right reservation class so an office has many reservations i think that's all we need we need to set this costs i've never used this survey yeah cast casting for the model it allows you to cast the attributes so whenever you retrieve the model from the database it's mostly or most of the uh fields will be represented by a string so using this casts array you can tell lukewarm to cast these attributes to these types before returning them to the code so these are the casts and what you can do with costs so here the casts attribute is inside the has attributes concern of the liquid model so it exists in every element model and it's protected all right so now let's move to the next and the next one is images oh yeah office will have a relationship with images as well so let's move to the image attribute or the image model and there's a path timestamps resource so that's something i need to check in the eloquent documentation so i'm going to the documentation at laravel.com docs and then i'm going to check look one relationships [Music] and i want a one too many no i want one no i want a one too many ah one too many polymorphic relationship like this so inside the image we are going to have to use morph tool so inside the image here we're going to have a function called resource and we're going to return this morph to and let's let phpstorm add the timing for us simplify so this is more too and inside the yeah inside the office model we're going to have a relationship called images and return this we will use for this one morph mini yeah morph many image class and then call it resource here so this should take care of the many-to-many polymorphic relationship all right so here we have the images ready i think so if you go to the image the image belongs to a resource and an office has multiple images using the morph menu relationship perfect so finally there is the reservation model reservation to php and let's see this one has a user so function user return this belongs to a user class and and it also belongs to an office let's just copy this and name it office so it belongs to an office and there's a price the price should be an integer so protected costs the price here should be an integer status should be an integer as well status should be an integer start date should be a date but we are going to use an immutable date and for the end date we are also going to use an immutable date here and the difference between immutable date and date is that using date will give us a mutable date object and by mutable it means if you're not familiar with the term if we make any changes if we change the state of the object of the date object the chain the this state will be preserved it will affect the original object but if we use a mutable date whenever we make a change to the date object that's returned the change will be applied on a fresh copy from the date object not the original date object itself maybe sometime in uh while building the application i will show you the difference between using an immutable date and a date so for this we need to use immutable date so i think that's it uh a reservation belongs to a user belongs to an office and these are the casts that we need i think that's it so let me check the commands real quick to make sure that i'm not missing anything hello from every coast hello you can use decimal a to keep the decimal places interesting decimal a to keep the decimal places you mean inside the the office here instead of decimal we can use decimal 8 here since in the office here we use eight places yeah i didn't know that this syntax works but thank you for letting me know we will test it out and make sure that it works now does casts act like filipino no that's completely different a cast our casting works when we retrieve the data from the database it will be casted before it is returned to us so if we want to cast the latitude as a decimal it will be returned as a decimal instead of a string so that's casting any other questions i don't think this is going to be safe to watch later of course this is going to live on the official laravel youtube channel so you guys can watch it later i think we're good let's comment what we just did and i'm sorry about that but i'm going to use web so this is an alias which so this is an alias i'm use which will which will just add the files and commit with a combat message and this comment message is going to we wep i'm sorry i'm uh i don't feel guilty for using web so let's continue which let's go back to the phpstorm and check the to-do list for today we have the models prepared and i think we have the factories paper but there are a couple of things that maybe i want to do so the factories database factories image factory nothing to do here office factory yes so let me do that now so the approval status here is an integer that says what's the status of the office that was added to the system we will allow people to add offices to the system whenever they want but we won't show but we will not show them for users to use to make reservations unless they are approved so by default when a new office is added to the system it's going to have an approval status of one and one means pending two means approved and three means rejected and i'm saving this as an integer instead of saving it as a string because if the database grows large if this system becomes huge uh searching or querying with an integer index is uh much easier on the mysql engine than on a string of course for like any kind of uh medium size application using a string is completely fine and we use it in many applications but i just thought with this application i'm going to use an integer just to explain to you guys what what's the benefits of using an integer here and there is a question that says why you don't use inums in this case and the problem with enums is that each time you need to add another status for the nm or another value for the enemy you need to run a migration and running migration will alter the database stable and will lock it during the migration but if i use it like this i can add a status to the system without having to modify the database i will just add another status let's see status number four and i will uh get push master and deploy and i will have the status ready without running any migrations without locking any tables without uh causing any downtime to my application so that's why i'm not using inums yeah so cloud you just answered the question again hi claudio it's good to have someone from the team joining the stream yeah oh he's also answering a lot of questions thank you claudio for helping so here we have the approval status as an integer but inside the office model here is what i'm going to do i'm going to declare a constant called approval pending that has a value of 1 another constant that says approval approved value 2 and 1 approval rejected for value three that's useful because instead of using integers here and then going back to search what this integer represent we can just use the constant so i'm gonna have approval approved here so we know by reading this code we know that the approval status is going to be or it's going to represent an approved status and if we just highlight this in php storm it's gonna tell us that the value under this constant is equal to two so that's one benefit of using it this way why use numbers instead of strings i just explained this so if you if you check the playback you will find the answer there so that's the approval status let's check the reservation it also has the status so let's go to the reservation model and declare a constant and this constant will be status active equals one and another status canceled equals two so here we're going to change this with reservation status active so all reservations created by the fake the fake or the factory is going to have a status of active i think that's it guys that's what we need so far so let's go to the todo oops right hopefully i didn't turn on debugging for anything so let's go to the to-do and prepare factories i think the factories are prepared for us we have the factories prepared the models now it's time to look into the resources and if you are not familiar with the resources since we are going to build an application that's api first resources represent or allow us to shape how we are going to display each and every resource to the end user in the form of json by default you can return an eloquent model instance or an instance of an eloquent collection and laravel is going to cast it to json by default for you but it's going to make decisions for you if we want to customize how the object will look like if you want for maybe you want to hide some attributes you want to add some attributes or conditionally add some attributes for example if the logged in user is let's say an admin you want to show the password for the admin you can do that using a resource by checking if the request is coming from an admin and show the attribute or not and you can do that in the resources so we are going to use api resources in this application since it's api first [Music] so let's start by creating resources we have let's check the models we need to create a user resource so first let's go to the terminal clear it and call php artisan make resource and call our first resource user resource all right oh that already exists let's see http resources we have the user resource already existing all right so let's move to the next model which is the office resource office resource and we also have the reservation resource and the tag resource and i think that's it reservation office or image resource so image resource let's see so all the resources are created under app http resources and we have all the resources that we just created all looks great by default the resource is going to return all the all the resource attributes out of the box so it's gonna call to array on the resource that's passed to it if it's an eloquent collection it's going to call to array on the liquid correct collection if it is a model it's going to call to array on the model so that's uh that's the resource that's the the default we are going to look into customizing this in the future if we need but for now we'll just stick to the defaults and then i'm gonna whip to just save what we just did so let's move to the doodle and we have the resource resources done quick look at the chat hidden right for file uploads create a trade can upload that's not a question oh i'm happy that you like the background music guys [Music] [Music] rust is asking what is this application doing i answered that at the beginning of the stream you can go back to the playback and you will find the answer [Music] all right so i think we're good no questions regarding what we just did so far so let's move to creating the tags since this is an api first application we're going to create our routes inside the routes api.php file let's remove this command from here and yes we're gonna use sanctum for the authentication but the end point that we are about to create doesn't require any authentication it's just available for anyone to list the tags so here get tags and we're gonna use the tag controller instead so tag control we created the controllers yesterday if you are not uh if you didn't notice guys yesterday so tag controller for the tag we only just need one method so we are going to call invoke so this will be an invokable controller and inside the controller we are going to return a tag resource collection and we'll just get all the tags from the database so calling tags or api slash tags should return all the tags in the system let's create a test to verify that art make test tags controller test now let's go to this tags controller test and try to make sure that it works so api tags and i want to actually see the response so i'm gonna dd response json so let's run tags controller php unit filter equal tags controller test and we can see that it's returning the tags all right the response is going to be an array and this array or an object adjacent object this json object has a key called data and under this key we have another array and the array has three items item number one is for tag one item number two for tag two and item number three for tag three so if you are not familiar with uh if you haven't hear me say this guys i'm not the kind i'm not a tdd kind of guy i don't do test driven development i write the code that i think will work and then i write the test that verify that the code works so that's that's how i work that's how my mind think it's not right or wrong that's that's how i think you don't have to do like me and definitely there are people who are much much smarter than me who would tell you otherwise so if you are comfortable with doing uh tester driven development you just listen to those people and do this driven development if your mind is wired like me and you don't really get tested driven development you can just do it like i do it you just spike like create the code write the code that you think will work and then stabilize by making sure that the code work works by writing tests let's move to the chat if this is an spa it can be an sp i haven't decided yet but we are going to make it ready to respond to any kind of client whether it's an sba a blade front end or a mobile application api development is what many of us needed glad you find this useful i think closed what means call me php call me web is just that i'm saying get i don't even remember what was it because i have this yeah it's get add all and then after running it at all i run git commat m and then pass the parameter that i passed to the commie function that i have on my system so it will it's just similar to get commet m whip that's it that's what the alias is for don't let it distract you [Music] are you using any specific design patterns now so far i'm not using any specific design patterns i'm just using the laravel conventions and building things so now we have the tags endpoint responding correctly let's make sure that all tests or the test path passes usually when i write a test i write it like this so test and then i say it lists tags and then i'm gonna copy this here and for the assertion i'm gonna assert that it returns 200 and i want to make sure that json contains i think a size a certain or a third count maybe this count a third count [Music] three and then response json data let's make sure that let's oh yeah so the this path so here i'm asserting that it's returning a data attribute inside the response and this data attribute has three tags so just to make sure that it all works but the number three here may change in the future if i decide to see the database with more tags in the beginning so this test will fail in the future so what do you think guys how we can make this test future proof we can just ensure that it's returning some tags and the first tag in the return assert instance off no because it's an array so not instance off so let's just make sure that it's returning a tag with an id and assert not none maybe that's enough yeah so the assertion here that we are making sure that this endpoint is returning a data attribute and has at least one value inside the data attribute and this value has an id so that's that's that assertion is enough i think to make sure that the api tags endpoint is working what do you think guys i'll take a look at the chat claudia is saying if you are bad with coming up with this names a great tip i picked up from adam watham is to try and finish the sentence the one where and your test name here yeah i think that's a good idea it's always hard to came up with names for anything not just tests so that's a good idea [Music] would be nice to assert the exact json again what i'm saying is that i might in the future have to add more tags to the migration so instead of the response is going to contain three tags it might contain 10 tags and that will have me change the test so i want to write a test that it doesn't that doesn't have or or is future proof that i don't have to change it in the future so that's why i'm not asserting a specific response coming from the endpoint i just need to make sure that it's working and it's returning tags and at least one tag with an id [Music] how about you assert the json structure yeah maybe maybe i look into that of uh off stream and we can i can show you this in the next stream before we continue but i don't remember the syntax right now and i don't want to waste time with it as i said the way i work is to spike and then stabilize i make sure that things work i just get what whatever green i can get as fast as possible and make sure that things work and then later i go back to the code and refactor it and make sure that it's well tested and make sure that the tests make sense and looks all right so that's that's how i work i spike i work on things pretty fast and reach a point where things are working and then i go back and stabilize that's how i work really enjoying this live coding format thank you romeos romo i i hope i'm not butchering your name thank you so much i'm glad you are enjoying could you just assert that the tag has a name of course there are many ways to assert that but i think this is enough that this endpoint is listing tags it doesn't require authentication doesn't require authorization anything anyone can hit this end point and is going to have an array of that of tags written so let's go back to the to-do and see what we find so far we have the routes we have the controller and we have the tests i think that's good let's go back and whip clear we're ready to go now it's time we look into the office's endpoint so here the tags just to make it easier to read in the future and here the end point for the offices offices and we are going to use the office controller and let's close this the office controller and for this endpoint we're going to head the index method so we will go to the office controller and create a method called index this method is going to return a response of course which one yes this one all right that's because it's not returning anything all right similar to the tags endpoint what we need to do here is to return an office resource collection and then pass the offices to this collection and for the offices we are going to office and then all maybe sort or what order buy yes is it order buy or sold by i think it's order pie yeah as much as i remember let's order by id desk so the most recent ones appear first for now this this is going to change a lot but for now just to make sure that things work we're going to use order pi and then get maybe let's use query here just to keep things organized and then offices of course phpstorm is complaining because the return type is something different all right let's give it what it wants so this should work we need to make sure that it works so let's create a test art make test offices controller right office controller office controller test right the test is created so let's go to it office controller test and let's call api offices and make sure that it's returning 200 and similar dd json the return json and let's go to the terminal php unit filter office controller test and it's returning empty data because we haven't seeded the database with any offices so let's just do that so we are going to call office the office model factory and create i think factory we can there is a way we can say count right 3 and it will create three offices for us and yeah here we go i think i remember there were factory three i think like this that does the same thing let's try yeah no no didn't work so count three it's not clearing the database between tests for some reason i don't remember why maybe because [Music] or refresh use refresh database right yeah here we go thanks so i think yeah if we do factory three and we remove the count here it will create three models for us right so the endpoint is working a data attribute and has three offices created by the factory [Music] all looks good so let me take a look at the chat the to-do extension is cool it's not an extension actually it's just a markdown file did you delete the stream from yesterday yes i did because it was a disaster you can add office query to get better autocomplete support yeah that's just what i did office query why not use the shorter office latest because latest let's see will it work yeah it works nice did it work no it's not working because you can see here that it's returning the uh what's going on oh it's latest by id so latest by id and then let's see yeah seems to be working so nice office the latest we can use it instead of order pi desk nice i didn't know that thank you why not use the shortest oh thank you someone for giving me a hint about this latest method it's really nice you can use response search status to 100 dumb to get the response content let's try that set status here and we can just do dump right nice all right that's really nice thank you uh sandor help me i'm sorry guys if i'm butchering your names thank you for this step you see like it's nice to do live streams because i learn things from you and you learn things from me that you might not know so this is like a two-way communication and a two-way learning platform so i'm really glad that i'm doing this live and that it's working i hope i hope i can do more in the future why are you setting the return types of function to index i don't think i understand the problem i understand the question oh there's also a cert okay and then dump let's try it wix thank you thank you davor and thank you claudio thank you claudio for this and yes the latest uses the uh created ad colon by default but for this we want to sort by id all right that's really cool i learned a lot of things today so let's see what we can assert here to make sure that all is all right maybe like the previous one where we assert not null and we get the response jason json data and zero and id or we can just assert oh no and we can also assert count response json data right so let's try that sir count must be of type integer array given that's the first we must say that it should be three all right and that works that's great let me check at the chat what do you guys think what else i should assert on this endpoint this end point just returns a list of offices available no need for authentication no need for authorization it should just return a list of offices so i think it's enough that we make sure that it's returning okay it's not erroring and that it's returning the expected count of offices that we created a third json count so json count you mean on the response here a third json count json count three will it work because there is a data attribute if you remember oh it doesn't work json count oh yeah we can say the key is data oh nice nice nice nice there are a lot of nice assertions here that i'm not familiar with so a third json count that's that's new actually like the thing about my job is that the most recent application that we built is weber and it's it was built two years ago so as a developer working in in the company the some of the most recent methods some of the most recent additions to the framework are things that i'm not familiar with because i didn't had to use them after they were created so that's why i'm not familiar with them it's really nice that i try to create applications out of nowhere just uh random ideas so i get uh familiar with how people or or get familiar with the things that that are needed while building applications with the most recent uh additions to the framework and i also think with the youtube videos that i've been doing for the past two months it's really good that i keep track of all the things that are added and that's how i personally gain knowledge of everything new so that's that's really a two-way benefit here you see oh i'm gonna take a quick look at the chat when you will take in consideration the status of a single office i am this end point shouldn't return an office that's not approved and it shouldn't return an office that should be hidden so that's why i use the query method here just to make things a little bit readable and this method is going or this end point this controller method is not done yet it's it's far from done i'm just making sure that it's working and then i will continue building on it and make sure that it filters the offices and not return anything and also it responds to user queries for example if a user is searching for an office uh that's uh that belongs to a specific user like his listing offices that belong to a specific host that he's comfortable with we will make sure that this query works but this the first time i write test or i write controller method i just try to assert that it works first before continuing adding more queries and refining the code [Music] all right [Music] why don't you chain functions instead of assigning to response what do you mean uh what do you mean by that cigar can you elaborate let's go back to the tudo and offices here we wanted to work on list offices and it's far from done we want to read lead office and that's pretty easy we can do it but i think we are almost out of time so we will just stop here today and then continue another time we will work on this end point and only view offices that should be viewable by users offices that are approved and offices that are not hidden and we will also allow users to filter offices by the user id and we will also implement badgination so if there are a lot of offices in the system we told we don't return them all at once we are going to paginate them so let's set the to-do for the next session we are going to first [Music] filter the offices returned and we are going to paginate the last office's endpoint and we are going to work on the show office endpoint and create office endpoint so this is to do next and for this stream we just finished this stuff so guys do you have any questions for me before i go let me know right in this get a third json count or you mean in the test here of this test oh so here a third get and gen then i do this and this yeah it works it's it's fine if we do that but i personally prefer this so i keep all the assertions at the bottom and if there is any code that i want right here i can do that thanks to the bug maybe i can do it right here so i like to keep the assertions at the end of the method that's that's my style so it has nothing to do with what's right or wrong it's just my style oh there are 142 concurrent users thanks guys for joining all right any questions do you have any questions for me before i go [Music] all right adries is asking why use query here in the office controller oh let me share my screen again so why use query because it will allow it will give me auto completion and it will allow me to make the code more readable instead of having to put latest here i want to have all the modifiers under each other so query here helps me do that so i think this session is over all right thank you everyone for joining me today i really appreciate it and i'm really happy with the outcome of this stream i'm looking forward for more streams like this we're gonna finish this application uh have and even extend it with the ideas that i shared at the beginning of the stream it's gonna be great and at the end of finishing this application we're going to look into deploying it to laravel forge on octane laravel forge on php fpm and laravel forge with envoyer zero downtime deployment and we are going to deploy it on laravel vapor as well and during the peld we are going to use laravel sparks we are going to cover a lot of the laravel ecosystem products and we are going to use community packages as well to make our code more readable more performant and more easy to write so this is the plan for the next streams thank you for joining me today and hope to see you soon [Music] [Music]
Info
Channel: Laravel
Views: 13,425
Rating: undefined out of 5
Keywords:
Id: 2RlbXNjhQkc
Channel Id: undefined
Length: 69min 55sec (4195 seconds)
Published: Fri Sep 10 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.