How to use Telescope Laravel 10 Example Tutorial

laravel-10-banner-1024x576

How to use Telescope Laravel 10 Example Tutorial – Brilliansolution. Laravel 10 telescope example; In this tutorial, you will learn how to install and configure telescope in Laravel 10. And how to use telescope in Laravel 10.

Using Laravel Telescope can debug requests, exceptions, databases, cache, and much more in real-time by accessing a specific route in your local or production environment in Laravel 10 app.

Contents

Laravel/Telescope for Laravel 10

Follow the below givens simple steps to install, configure and use telescope in Laravel 10:

Step 1 – Install Telescope

In this step, open command prompt and navigate to your Laravel 10 app by using this command:

cd /project folder name

And run the following command to install telescope in Laravel 10 app:

composer require laravel/telescope

If you want to use telescope in local environment, so you can use the below command:

composer require laravel/telescope --dev

Step 2 – Migrate Tables

In this step, run the following commands on command prompt to migrate tables into database:

php artisan telescope:install

php artisan migrate

Step 3 – Configure Telescope

In this step, an open app.php file, which is located inside the config directory. And configure telescope providers in Laravel 10 app:

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:

public function register()
{
    if ($this->app->isLocal()) {
        $this->app->register(\Laravel\Telescope\TelescopeServiceProvider::class);
        $this->app->register(TelescopeServiceProvider::class);
    }
}

Step 4 – Configure Dashboard Authorization

In this step, Telescope exposes a dashboard at /telescope. By default, you will only be able to access this dashboard in the local environment. Within your app/Providers/TelescopeServiceProvider.php file, there is a gate method. This authorization gate controls access to Telescope in non-local environments. You are free to modify this gate as needed to restrict access to your Telescope installation:

protected function gate()
{
    Gate::define('viewTelescope', function ($user) {
        return in_array($user->email, [
            'taylor@laravel.com',
        ]);
    });
}

Step 5 – Start Development Server

In this step, run the following command on command prompt to start developement server:

php artisan serve

Step 6 – Test Laravel Telescope

Now, open your browser and use the following command to test Laravel 10 telescope:

http://127.0.0.1:8000/telescope

brillian

Leave a Reply

%d bloggers like this: