Laravel 5.8 – From The Ground Up
Lesson 41 of 52 · Laravel 5.8 Tutorial From Scratch – e41 – Telescope · Education
Laravel 5.8 Tutorial From Scratch – e41 – Telescope
as part of the laravel eco system there is a utility called laravel telescope it is actually maintained by the core laravel team and it is a way for us to
tap into our application and find out what's going on behind the scenes now this tool is incredibly powerful but incredibly simple to install and this is something that will help newcomers
tremendously so I am inside the documentation for laravel telescope you can Google Lenovo telescope but I will put the link down below in the description so let's read through the
introduction and find out how to do the installation so it looks like a simple composer required which we've done before then we need to run a couple of PHP artisan commands to install it and
then another one to migrate our database and that's it with those three commands we are good to go now there is this section here talking about how to only install in a
specific environment now we have not touched up on the subject just yet but composer is able to have different requirements for production and different requirements for your
development environment and this is very powerful for something like telescope if you only want a telescope to be available during the development process but you do not want to deploy that to
production that's what you would do you would add the – – dev and that will put telescope in a separate part of your composer of that JSON file that is only installed if you are in local
environment alright let's dive right in and get this installed I'm going to compose a require level telescope in our project and let's wait for it to install and it's done now do notice here that we
have a new discovered package which is of course the letter ville telescope let's head back to the documentation and find out what's next so now we need to run PHP artisan telescope install let's
run that now and there we go and finally let's go ahead and migrate our database so we see that telescope created a new table in our database called telescope entries great so now we
can go back to the browser and in our app we can visit our app telescope so this is laravel telescope now we're gonna do a quick overview of telescope but I definitely encourage you
to spend some time with it trying to look through it and see how it works so we have this requests and the way that would work is if we visit our project in a separate screen we go back here and we
do see that we had two requests we obviously try to fetch the customers and then we had a redirect back to the login page all right so back here let's try to go to the contact us page and let's
check out what happened load new entries and there we are so we can see that behind the scenes telescope is continually looking in our app and telling you what's going on so obviously
if we go to the commands section very similar section here let's run a command let's go back to our terminal run PHP artisan let's go back load new entries and now we see that we ran the list
command obviously the list command is just when we run PHP artisan it gives us a list of commands so that's pretty cool now when we did our jobs before obviously this is where they would go
between schedules and jobs exceptions if we have a runtime error exception that's where those would go we have access to our logs and dumps in queries so this section is very cool we're actually able
to see every single query that we're running behind the scenes so for example if we load it up our customers list we go ahead and register a user very quickly so I can log in test user all
right so let me visit the customers list so we have one customer here so now we see that we loaded our customers and then we loaded our companies and the reason for that is that our company is
actually being lazy loaded through our relationship let's go back to phpstorm so I can show you that let's go to the customers index and if we look down here you see that customer is calling the
company relationship and then calling the name so this actually brings us to a problem we're gonna solve this in the neck episode but check this out if we
actually generated a lot of customers you're gonna see we're gonna end up with a lot of duplicated queries so let's do that now let's go to PHP artisan tinker and let's use our factories to whip up
let's say 50 customers whoops start again there we go so now we have a lot of customers go back to our browser hit refresh and now you see we have a lot of customers but now if we load
telescope we have what is called an n +1 problem so we're actually gonna solve this in the next episode but check out how many queries we are running with that simple operation now of course if
we were to add even more customers it keeps getting even worse so that is an important thing to remember so in the next episode we're gonna take a look at how to fix this so that we keep our
queries to a very very minimum count so stick around
Laravel Telescope provides incredible feedback on what is going on behind the scenes with your application. It is an extremely powerful tool but very simple to install. Follow along as we install and do an overview on Laravel Telescope.
For the best experience, follow along in our interactive school at https://www.coderstape.com
Laravel Telescope
https://laravel.com/docs/5.8/telescope
DigitalOcean Referral
https://m.do.co/c/7dce5364ef4d
Resources
Course Source Code
https://github.com/coderstape/laravel-58-from-scratch
Hit us up on Twitter with any questions or comments @codertape (https://twitter.com/CodersTape)
About This Course
Ready to get started on your path to Laravel Artisan? In this series, we are breaking down all of the basics of Laravel to get you comfortable using the world’s most popular PHP framework. Let’s get started!