In this tutorial you will learn about the Laravel 8 Telescope Example Tutorial and its application with practical example.
In this Laravel 8 Telescope Example Tutorial I will show you how to install and configure telescope in laravel 8. In this tutorial you will learn to install and use telescope in laravel 8. Laravel Telescope can be used to debug requests, exceptions, databases, cache, and much more in real-time by accessing a specific route in your local or production environment in laravel 8 project.
Laravel 8 Telescope Example Tutorial
In this step by step Laravel 8 Telescope Example Tutorial you will learn to install, configure and use telescope in laravel 8. Please follow instruction given below:
Step 1 – Install Telescope
In this step you are required to switch to project directory and then run the following command to install telescope in laravel 8 app:
1 |
composer require laravel/telescope |
If you want to use telescope in local environment, so you can use the below command:
1 |
composer require laravel/telescope --dev |
Step 2 – Migrate Tables
Now, run following command to migrate database schema.
1 2 3 |
php artisan telescope:install php artisan migrate |
Step 3 – Configure Telescope
Now we need to configure Telescope, please follow instruction
1 |
App\Providers\TelescopeServiceProvider::class, |
After that, open AppServiceProvider.php file, which is located inside app/providers directory and add the following lines of code into register() method:
1 2 3 4 5 6 7 |
public function register() { if ($this->app->isLocal()) { $this->app->register(\Laravel\Telescope\TelescopeServiceProvider::class); $this->app->register(TelescopeServiceProvider::class); } } |
Step 4 – Configure Dashboard Authorization
Telescope exposes a dashboard at /telescope
. You can access this dashboard in the local
environment. Go to app/Providers/TelescopeServiceProvider.php
file, there is a gate
method. This authorization gate controls access to Telescope in non-local environments. From here you can modify this gate as needed to restrict access to your Telescope installation:
1 2 3 4 5 6 7 8 |
protected function gate() { Gate::define('viewTelescope', function ($user) { return in_array($user->email, [ 'taylor@laravel.com', ]); }); } |
Step 5 – Start Development Server
Now we are ready to run our example so lets start the development server using following artisan command –
1 |
php artisan serve |
Step 6 – Test Laravel Telescope
Now, open the following URL in browser to see the output –
1 |
http://127.0.0.1:8000/telescope |