3
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Laravelのコードをワンライナーで実行する

Posted at

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です!

3
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?