diff --git a/docs/content/docs/4.laravel/1.laravel-automations.md b/docs/content/docs/4.laravel/1.laravel-automations.md index a37ac392..b1f7bee4 100644 --- a/docs/content/docs/4.laravel/1.laravel-automations.md +++ b/docs/content/docs/4.laravel/1.laravel-automations.md @@ -23,6 +23,7 @@ In order for this script to run,`AUTORUN_ENABLED` must be set to `true`. Once th | `AUTORUN_LARAVEL_MIGRATION_ISOLATION` | `false` | Run your migrations with the [`--isolated`](https://laravel.com/docs/12.x/migrations#running-migrations) flag.
**ℹ️ Note:** Requires Laravel v9.38.0+ | | `AUTORUN_LARAVEL_MIGRATION_TIMEOUT` | `30` | Number of seconds to wait for database connection before timing out during migrations. | | `AUTORUN_LARAVEL_OPTIMIZE` | `true` | `php artisan optimize`: Optimizes the application. | +| `AUTORUN_LARAVEL_SEED` | `false` | `php artisan db:seed`: Runs the default seeder.
**ℹ️ Note:** Set to `true` to run the default seeder. If you want to run a custom seeder, set this to the name of the seeder class. | | `AUTORUN_LARAVEL_ROUTE_CACHE` | `true` | `php artisan route:cache`: Caches the routes. | | `AUTORUN_LARAVEL_STORAGE_LINK` | `true` | `php artisan storage:link`: Creates a symbolic link from `public/storage` to `storage/app/public`. | | `AUTORUN_LARAVEL_VIEW_CACHE` | `true` | `php artisan view:cache`: Caches the views. | @@ -65,6 +66,11 @@ This command caches all configuration files into a single file, which can then b [Read more about configuration caching →](https://laravel.com/docs/12.x/configuration#configuration-caching) +## php artisan db:seed +This command runs the default seeder. If you want to run a custom seeder, set `AUTORUN_LARAVEL_SEED` to the name of the seeder class. + +[Read more about seeding →](https://laravel.com/docs/12.x/seeding) + ## php artisan route:cache This command caches the routes, dramatically decrease the time it takes to register all of your application's routes. After running this command, your cached routes file will be loaded on every request. diff --git a/src/common/etc/entrypoint.d/50-laravel-automations.sh b/src/common/etc/entrypoint.d/50-laravel-automations.sh index 5b33e2b8..f60af69d 100644 --- a/src/common/etc/entrypoint.d/50-laravel-automations.sh +++ b/src/common/etc/entrypoint.d/50-laravel-automations.sh @@ -24,6 +24,9 @@ script_name="laravel-automations" : "${AUTORUN_LARAVEL_MIGRATION_ISOLATION:=false}" : "${AUTORUN_LARAVEL_MIGRATION_TIMEOUT:=30}" +# Set default values for seeders +: "${AUTORUN_LARAVEL_SEED:=false}" + # Set default values for Laravel version INSTALLED_LARAVEL_VERSION="" @@ -136,7 +139,7 @@ artisan_optimize() { [ "$AUTORUN_LARAVEL_VIEW_CACHE" = "false" ] && except="${except:+${except},}views" [ "$AUTORUN_LARAVEL_EVENT_CACHE" = "false" ] && except="${except:+${except},}events" - echo "🛠️ Running optimizations: \"php artisan optimize ${except:+--except=${except}}\"..." + echo "🚀 Running optimizations: \"php artisan optimize ${except:+--except=${except}}\"..." if ! php "$APP_BASE_DIR/artisan" optimize ${except:+--except=${except}}; then echo "$script_name: ❌ Laravel optimize failed" return 1 @@ -174,6 +177,18 @@ artisan_optimize() { return $has_error } +artisan_seed(){ + # Run the default seeder if "true", otherwise use value as custom seeder + if [ "${AUTORUN_LARAVEL_SEED}" = "true" ]; then + echo "🚀 Running default seeder: \"php artisan db:seed\"" + php "${APP_BASE_DIR}/artisan" db:seed --force + else + echo "🚀 Running custom seeder: \"php artisan db:seed --seeder=${AUTORUN_LARAVEL_SEED}\"" + echo "ℹ️ Your application must have a seeder class named \"${AUTORUN_LARAVEL_SEED}\" or this command will fail." + php "${APP_BASE_DIR}/artisan" db:seed --seeder="${AUTORUN_LARAVEL_SEED}" + fi +} + get_laravel_version() { # Return cached version if already set if [ -n "$INSTALLED_LARAVEL_VERSION" ]; then @@ -314,6 +329,10 @@ if laravel_is_installed; then artisan_migrate fi + if [ "$AUTORUN_LARAVEL_SEED" != "false" ]; then + artisan_seed + fi + if [ "$AUTORUN_LARAVEL_OPTIMIZE" = "true" ] || \ [ "$AUTORUN_LARAVEL_CONFIG_CACHE" = "true" ] || \ [ "$AUTORUN_LARAVEL_ROUTE_CACHE" = "true" ] || \