使用env变量prepend命令 - 包括子命令

I need to add an environment variable to the php artisan migrate commands of Laravel for use with docker, like:

env DB_HOST=127.0.0.1 php artisan migrate

I created a function in my .zshrc file like this:

function migrate() {
  (env DB_HOST=127.0.0.1 php artisan migrate $*)
}

however the way Laravel's command structure works is like this:

 migrate
  migrate:install      Create the migration repository
  migrate:refresh      Reset and re-run all migrations
  migrate:reset        Rollback all database migrations
  migrate:rollback     Rollback the last database migration
  migrate:status       Show the status of each migration

so this doesn't work for a command like this:

migrate:refresh --seed

is there a way I can write the function to also add the variable for all these 'child' commands too?

I assume you want to be able to do this: migrate refresh --seed, then

migrate() {
  local subcommand=$1
  shift
  env DB_HOST=127.0.0.1 php artisan migrate:"$subcommand" "${@}")
}

Hmmm, perhaps

artisan() {
  env DB_HOST=127.0.0.1 php artisan "${@}")
}
for subcommand in    \
    migrate          \
    migrate:install  \
    migrate:refresh  \
    migrate:reset    \
    migrate:rollback \
    migrate:status
do
    alias $subcommand="artisan $subcommand"
done

That would get you some tab completion for free as well.

artisan() {
  env DB_HOST=127.0.0.1 \

  php artisan "${@}"
}

The generic function for Laravel+Docker users to have the flexibility to update environment variables for use with artisan outside docker containers.

Thanks to @glenn-jackman for pointing me in the right direction!