Laravel5.7 + Telescope（Install編）

## 概要

[laravel/telescope](https://github.com/laravel/telescope)はLaravel用のデバッグ支援ツールです。
Telescope(テレスコープ)は望遠鏡という意味らしいです😇
Requests, Commands, Schedule, Jobs, Exceptions, Logs, Dumps, Queries, Models, Events, Mail, Notifications, Cache, Redis等、実行ログを監視します。
Telescopeを導入するとデバッグコードを仕込むことなく、対象の情報について洞察できます。
Laravelのローカル開発環境でのデバッグがとても楽なものになります。

## シリーズ記事

- Laravel5.7 + Telescope（Install編）
- [Laravel5.7 + Telescope（Config編）](https://qiita.com/ucan-lab/items/bfb4806c76b225cd5301)

## Laravelバージョン

```shell-session
$ php artisan --version
Laravel Framework 5.7.11
```

Laravel Telescopeは **Laravel5.7.7** 以上が必要です。

## laravel-telescopeのインストール(エラー)

```shell-session
$ composer require laravel/telescope --dev

Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - moontoast/math 1.1.2 requires ext-bcmath * -> the requested PHP extension bcmath is missing from your system.
    - moontoast/math 1.1.1 requires ext-bcmath * -> the requested PHP extension bcmath is missing from your system.
    - moontoast/math 1.1.0 requires ext-bcmath * -> the requested PHP extension bcmath is missing from your system.
    - laravel/telescope v0.1.2 requires moontoast/math ^1.1 -> satisfiable by moontoast/math[1.1.0, 1.1.1, 1.1.2].
    - Installation request for laravel/telescope ^0.1.2 -> satisfiable by laravel/telescope[v0.1.2].

  To enable extensions, verify that they are enabled in your .ini files:
    - /usr/local/etc/php/php.ini
    - /usr/local/etc/php/conf.d/docker-php-ext-intl.ini
    - /usr/local/etc/php/conf.d/docker-php-ext-pdo_mysql.ini
    - /usr/local/etc/php/conf.d/docker-php-ext-sodium.ini
  You can also run `php --ini` inside terminal to see which files are used by PHP in CLI mode.
```

PHPのBCMath拡張機能がないのでTelescopeインストールでエラーとなりました。

## bcmath拡張機能をインストールする

[PHP BCMath 任意精度数学関数](http://php.net/manual/ja/book.bc.php)

```shell-session
$ docker-php-ext-install bcmath
$ php -m | grep bcmath
bcmath
```

docker使ってたので、bcmath拡張機能をインストールしました。

## laravel-telescopeのインストール(リトライ)

```shell-session
$ composer require laravel/telescope --dev
Using version ^0.1.2 for laravel/telescope
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 2 installs, 0 updates, 0 removals
  - Installing moontoast/math (1.1.2): Downloading (100%)
  - Installing laravel/telescope (v0.1.2): Downloading (100%)
Writing lock file
Generating optimized autoload files
> Illuminate\Foundation\ComposerScripts::postAutoloadDump
> @php artisan package:discover
Discovered Package: beyondcode/laravel-dump-server
Discovered Package: fideloper/proxy
Discovered Package: folklore/graphql
Discovered Package: laravel/telescope
Discovered Package: laravel/tinker
Discovered Package: nesbot/carbon
Discovered Package: nunomaduro/collision
Discovered Package: sentry/sentry-laravel
Package manifest generated successfully.
```

laravel-telescopeのインストールが成功しました！

## laravel-telescopeバージョン

```shell-session
$ composer show laravel/telescope | grep version
versions : * v0.1.2
```

## laravel-telescopeの設定

```shell-session
$ php artisan telescope:install
Publishing Telescope Service Provider...
Publishing Telescope Assets...
Publishing Telescope Configuration...
Telescope scaffolding installed successfully.
```

- `app/Providers/TelescopeServiceProvider.php`
- `config/app.php`
- `config/telescope.php`
- `public/vendor/telescope/app-dark.css`
- `public/vendor/telescope/app.css`
- `public/vendor/telescope/app.js`
- `public/vendor/telescope/mix-manifest.json`

上記のファイルが生成されました。

## laravel-telescopeのマイグレーション

https://github.com/laravel/telescope/blob/1.0/src/Storage/migrations/2018_08_08_100000_create_telescope_entries_table.php

このマイグレーションファイルが実行されます。

```shell-session
$ php artisan migrate
Migrating: 2018_08_08_100000_create_telescope_entries_table
Migrated:  2018_08_08_100000_create_telescope_entries_table
```

- telescope_entries_tags
- telescope_entries
- telescope_monitoring

上記のテーブルが生成されます。

## laravel-telescopeで追加されるルート

```shell-session
$ php artisan route:list
+--------+----------+-----------------------------------------------+--------------------+-------------------------------------------------------------------+------------+
| Domain | Method   | URI                                           | Name               | Action                                                            | Middleware |
+--------+----------+-----------------------------------------------+--------------------+-------------------------------------------------------------------+------------+
|        | POST     | telescope/telescope-api/cache                 |                    | Laravel\Telescope\Http\Controllers\CacheController@index          | telescope  |
|        | GET|HEAD | telescope/telescope-api/cache/{id}            |                    | Laravel\Telescope\Http\Controllers\CacheController@show           | telescope  |
|        | POST     | telescope/telescope-api/commands              |                    | Laravel\Telescope\Http\Controllers\CommandsController@index       | telescope  |
|        | GET|HEAD | telescope/telescope-api/commands/{id}         |                    | Laravel\Telescope\Http\Controllers\CommandsController@show        | telescope  |
|        | POST     | telescope/telescope-api/dumps                 |                    | Laravel\Telescope\Http\Controllers\DumpController@index           | telescope  |
|        | POST     | telescope/telescope-api/events                |                    | Laravel\Telescope\Http\Controllers\EventsController@index         | telescope  |
|        | GET|HEAD | telescope/telescope-api/events/{id}           |                    | Laravel\Telescope\Http\Controllers\EventsController@show          | telescope  |
|        | POST     | telescope/telescope-api/exceptions            |                    | Laravel\Telescope\Http\Controllers\ExceptionController@index      | telescope  |
|        | GET|HEAD | telescope/telescope-api/exceptions/{id}       |                    | Laravel\Telescope\Http\Controllers\ExceptionController@show       | telescope  |
|        | POST     | telescope/telescope-api/jobs                  |                    | Laravel\Telescope\Http\Controllers\QueueController@index          | telescope  |
|        | GET|HEAD | telescope/telescope-api/jobs/{id}             |                    | Laravel\Telescope\Http\Controllers\QueueController@show           | telescope  |
|        | POST     | telescope/telescope-api/logs                  |                    | Laravel\Telescope\Http\Controllers\LogController@index            | telescope  |
|        | GET|HEAD | telescope/telescope-api/logs/{id}             |                    | Laravel\Telescope\Http\Controllers\LogController@show             | telescope  |
|        | POST     | telescope/telescope-api/mail                  |                    | Laravel\Telescope\Http\Controllers\MailController@index           | telescope  |
|        | GET|HEAD | telescope/telescope-api/mail/{id}             |                    | Laravel\Telescope\Http\Controllers\MailController@show            | telescope  |
|        | GET|HEAD | telescope/telescope-api/mail/{id}/download    |                    | Laravel\Telescope\Http\Controllers\MailEmlController@show         | telescope  |
|        | GET|HEAD | telescope/telescope-api/mail/{id}/preview     |                    | Laravel\Telescope\Http\Controllers\MailHtmlController@show        | telescope  |
|        | POST     | telescope/telescope-api/models                |                    | Laravel\Telescope\Http\Controllers\ModelsController@index         | telescope  |
|        | GET|HEAD | telescope/telescope-api/models/{id}           |                    | Laravel\Telescope\Http\Controllers\ModelsController@show          | telescope  |
|        | POST     | telescope/telescope-api/monitored-tags        |                    | Laravel\Telescope\Http\Controllers\MonitoredTagController@store   | telescope  |
|        | GET|HEAD | telescope/telescope-api/monitored-tags        |                    | Laravel\Telescope\Http\Controllers\MonitoredTagController@index   | telescope  |
|        | POST     | telescope/telescope-api/monitored-tags/delete |                    | Laravel\Telescope\Http\Controllers\MonitoredTagController@destroy | telescope  |
|        | POST     | telescope/telescope-api/notifications         |                    | Laravel\Telescope\Http\Controllers\NotificationsController@index  | telescope  |
|        | GET|HEAD | telescope/telescope-api/notifications/{id}    |                    | Laravel\Telescope\Http\Controllers\NotificationsController@show   | telescope  |
|        | POST     | telescope/telescope-api/queries               |                    | Laravel\Telescope\Http\Controllers\QueriesController@index        | telescope  |
|        | GET|HEAD | telescope/telescope-api/queries/{id}          |                    | Laravel\Telescope\Http\Controllers\QueriesController@show         | telescope  |
|        | POST     | telescope/telescope-api/redis                 |                    | Laravel\Telescope\Http\Controllers\RedisController@index          | telescope  |
|        | GET|HEAD | telescope/telescope-api/redis/{id}            |                    | Laravel\Telescope\Http\Controllers\RedisController@show           | telescope  |
|        | POST     | telescope/telescope-api/requests              |                    | Laravel\Telescope\Http\Controllers\RequestsController@index       | telescope  |
|        | GET|HEAD | telescope/telescope-api/requests/{id}         |                    | Laravel\Telescope\Http\Controllers\RequestsController@show        | telescope  |
|        | POST     | telescope/telescope-api/schedule              |                    | Laravel\Telescope\Http\Controllers\ScheduleController@index       | telescope  |
|        | GET|HEAD | telescope/telescope-api/schedule/{id}         |                    | Laravel\Telescope\Http\Controllers\ScheduleController@show        | telescope  |
|        | GET|HEAD | telescope/{view?}                             |                    | Laravel\Telescope\Http\Controllers\HomeController@index           | telescope  |
+--------+----------+-----------------------------------------------+--------------------+-------------------------------------------------------------------+------------+
```

## Laravel Telescope 画面

http://127.0.0.1:8000/telescope

![スクリーンショット 2018-10-25 16.34.52.png](https://qiita-image-store.s3.amazonaws.com/0/52879/dbaec1e4-b68b-c56a-d653-ff52050650ff.png)

Laravel Telescopeの画面が表示されればokです😊