GitHub Actions上でLaravelのコードを実行して設定内容が正しく反映されているか確認したい欲求がありました。
$ php artisan tinker -h
Description:
Interact with your application
Usage:
tinker [options] [--] [<include>...]
Arguments:
include Include file(s) before starting tinker
Options:
--execute[=EXECUTE] Execute the given code using Tinker
-h, --help Display help for the given command. When no command is given display help for the list command
-q, --quiet Do not output any message
-V, --version Display this application version
--ansi Force ANSI output
--no-ansi Disable ANSI output
-n, --no-interaction Do not ask any interactive question
--env[=ENV] The environment the command should run under
-v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
tinkerのオプションを確認すると--execute
オプションを使うといいみたいです。
$ php artisan tinker --execute "dump(config('database.connections.mysql'))"
array:15 [
"driver" => "mysql"
"url" => null
"host" => "db"
"port" => "3306"
"database" => "laravel_local"
"username" => "phper"
"password" => "secret"
"unix_socket" => ""
"charset" => "utf8mb4"
"collation" => "utf8mb4_unicode_ci"
"prefix" => ""
"prefix_indexes" => true
"strict" => true
"engine" => null
"options" => []
]
Laravelのconfig関数が実行できて、結果をdumpできました!
そうそう必要な機会はないと思いますが、知っておくと便利なtipsです!