From 747a39ac0c3a0d5093366eeaf7edd29d3f3a97ed Mon Sep 17 00:00:00 2001 From: OrbisK Date: Tue, 20 May 2025 15:51:04 +0200 Subject: [PATCH 1/2] feat: use laravel sail --- .env.example | 14 +++++----- .gitignore | 3 ++- README.md | 65 ++++++++++++++++++++++++++++++++++++++-------- composer.json | 14 ++-------- composer.lock | 14 +++++----- docker-compose.yml | 55 +++++++++++++++++++++++++++++++++++++++ phpunit.xml | 3 +-- 7 files changed, 128 insertions(+), 40 deletions(-) create mode 100644 docker-compose.yml diff --git a/.env.example b/.env.example index 8f00f47..e52522c 100644 --- a/.env.example +++ b/.env.example @@ -20,12 +20,12 @@ LOG_STACK=single LOG_DEPRECATIONS_CHANNEL=null LOG_LEVEL=debug -DB_CONNECTION=sqlite -# DB_HOST=127.0.0.1 -# DB_PORT=3306 -# DB_DATABASE=laravel -# DB_USERNAME=root -# DB_PASSWORD= +DB_CONNECTION=mysql +DB_HOST=mysql +DB_PORT=3306 +DB_DATABASE=laravel +DB_USERNAME=sail +DB_PASSWORD=password SESSION_DRIVER=database SESSION_LIFETIME=120 @@ -65,4 +65,4 @@ AWS_USE_PATH_STYLE_ENDPOINT=false VITE_APP_NAME="${APP_NAME}" # Production license for @nuxt/ui-pro, get one at https://ui.nuxt.com/pro/purchase -NUXT_UI_PRO_LICENSE= \ No newline at end of file +NUXT_UI_PRO_LICENSE= diff --git a/.gitignore b/.gitignore index 5e2026f..3e596ff 100644 --- a/.gitignore +++ b/.gitignore @@ -28,4 +28,5 @@ yarn-error.log # Auto-generated type declarations auto-imports.d.ts -components.d.ts \ No newline at end of file +components.d.ts +.pnpm-store diff --git a/README.md b/README.md index 2ea894e..557e4db 100644 --- a/README.md +++ b/README.md @@ -2,40 +2,83 @@ [![Nuxt UI Pro](https://img.shields.io/badge/Made%20with-Nuxt%20UI%20Pro-00DC82?logo=nuxt&labelColor=020420)](https://ui.nuxt.com/pro) -This Laravel starter is based on [laravel/vue-starter-kit](https://github.com/laravel/vue-starter-kit) and demonstrate how to use [Nuxt UI Pro](https://ui.nuxt.com/pro) in a [Laravel](https://laravel.com/) application using [Inertia.js](https://inertiajs.com/). +This Laravel starter is based on [laravel/vue-starter-kit](https://github.com/laravel/vue-starter-kit) and demonstrate +how to use [Nuxt UI Pro](https://ui.nuxt.com/pro) in a [Laravel](https://laravel.com/) application +using [Inertia.js](https://inertiajs.com/). - [Documentation](https://ui.nuxt.com/getting-started/installation/pro/vue) ## Setup -Make sure to install the dependencies: +Copy the example environment file to create your .env file: ```bash -pnpm install +cp .env.example .env ``` -Copy the example environment file to create your .env file: +Install all composer deps: ```bash -cp .env.example .env +docker run --rm \ + -u "$(id -u):$(id -g)" \ + -v "$(pwd):/var/www/html" \ + -w /var/www/html \ + laravelsail/php84-composer:latest \ + composer install --ignore-platform-reqs +``` + +> [!NOTE] +> After you installed the dependencies, you can use composer commands via `./vendor/bin/sail composer install` or +`sail composer install` if you have it aliased in your shell. + +Start all containers + +```bash +./vendor/bin/sail up -d +``` + +Install all npm deps: + +```bash +./vendor/bin/sail pnpm install ``` Generate a new application key for your Laravel application: ```bash -php artisan key:generate +./vendor/bin/sail artisan key:generate ``` -Set up your database by running the migrations: +Migrate the database: ```bash -php artisan migrate +./vendor/bin/sail artisan migrate # --seed if you want to seed the database ``` -## Development Server +## Development -Start the development server on `http://localhost:8000`: +To start the development server, run: ```bash -composer run dev +./vendor/bin/sail up -d ``` + +```bash +./vendor/bin/sail pnpm dev +``` + +Open http://localhost in your browser. + +To use SSR you need to run the following command in a separate terminal: + +```bash +./vendor/bin/sail pnpm build:ssr +``` + +```bash +./vendor/bin/sail artisan inertia:start-ssr +``` + +Open http://localhost in your browser, you should see the SSR version of the app. (No HMR in this mode) + +To enable client-side hydration, please refer to the [Inertia Docs](https://inertiajs.com/server-side-rendering#client-side-hydration) diff --git a/composer.json b/composer.json index fd9eb66..cc2d835 100644 --- a/composer.json +++ b/composer.json @@ -17,9 +17,8 @@ }, "require-dev": { "fakerphp/faker": "^1.23", - "laravel/pail": "^1.2.2", "laravel/pint": "^1.18", - "laravel/sail": "^1.41", + "laravel/sail": "^1.43", "mockery/mockery": "^1.6", "nunomaduro/collision": "^8.6", "pestphp/pest": "^3.8", @@ -53,15 +52,6 @@ "@php -r \"file_exists('database/database.sqlite') || touch('database/database.sqlite');\"", "@php artisan migrate --graceful --ansi" ], - "dev": [ - "Composer\\Config::disableProcessTimeout", - "npx concurrently -c \"#93c5fd,#c4b5fd,#fb7185,#fdba74\" \"php artisan serve\" \"php artisan queue:listen --tries=1\" \"php artisan pail --timeout=0\" \"npm run dev\" --names=server,queue,logs,vite" - ], - "dev:ssr": [ - "npm run build:ssr", - "Composer\\Config::disableProcessTimeout", - "npx concurrently -c \"#93c5fd,#c4b5fd,#fb7185,#fdba74\" \"php artisan serve\" \"php artisan queue:listen --tries=1\" \"php artisan pail --timeout=0\" \"php artisan inertia:start-ssr\" --names=server,queue,logs,ssr" - ], "test": [ "@php artisan config:clear --ansi", "@php artisan test" @@ -83,4 +73,4 @@ }, "minimum-stability": "stable", "prefer-stable": true -} \ No newline at end of file +} diff --git a/composer.lock b/composer.lock index 973c594..f0196af 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "b69c7a6419170e02b2a078b6c41fceee", + "content-hash": "500ed5ce8ca56d5e21772413f2bdc1b6", "packages": [ { "name": "brick/math", @@ -6519,16 +6519,16 @@ }, { "name": "laravel/sail", - "version": "v1.42.0", + "version": "v1.43.0", "source": { "type": "git", "url": "https://github.com/laravel/sail.git", - "reference": "2edaaf77f3c07a4099965bb3d7dfee16e801c0f6" + "reference": "71a509b14b2621ce58574274a74290f933c687f7" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/laravel/sail/zipball/2edaaf77f3c07a4099965bb3d7dfee16e801c0f6", - "reference": "2edaaf77f3c07a4099965bb3d7dfee16e801c0f6", + "url": "https://api.github.com/repos/laravel/sail/zipball/71a509b14b2621ce58574274a74290f933c687f7", + "reference": "71a509b14b2621ce58574274a74290f933c687f7", "shasum": "" }, "require": { @@ -6578,7 +6578,7 @@ "issues": "https://github.com/laravel/sail/issues", "source": "https://github.com/laravel/sail" }, - "time": "2025-04-29T14:26:46+00:00" + "time": "2025-05-13T13:34:34+00:00" }, { "name": "mockery/mockery", @@ -9154,4 +9154,4 @@ }, "platform-dev": {}, "plugin-api-version": "2.6.0" -} \ No newline at end of file +} diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..c5b0406 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,55 @@ +services: + laravel.test: + build: + context: ./vendor/laravel/sail/runtimes/8.4 + dockerfile: Dockerfile + args: + WWWGROUP: '${WWWGROUP}' + image: sail-8.4/app + extra_hosts: + - 'host.docker.internal:host-gateway' + ports: + - '${APP_PORT:-80}:80' + - '${VITE_PORT:-5173}:${VITE_PORT:-5173}' + environment: + WWWUSER: '${WWWUSER}' + LARAVEL_SAIL: 1 + XDEBUG_MODE: '${SAIL_XDEBUG_MODE:-off}' + XDEBUG_CONFIG: '${SAIL_XDEBUG_CONFIG:-client_host=host.docker.internal}' + IGNITION_LOCAL_SITES_PATH: '${PWD}' + volumes: + - '.:/var/www/html' + networks: + - sail + depends_on: + - mysql + mysql: + image: 'mysql/mysql-server:8.0' + ports: + - '${FORWARD_DB_PORT:-3306}:3306' + environment: + MYSQL_ROOT_PASSWORD: '${DB_PASSWORD}' + MYSQL_ROOT_HOST: '%' + MYSQL_DATABASE: '${DB_DATABASE}' + MYSQL_USER: '${DB_USERNAME}' + MYSQL_PASSWORD: '${DB_PASSWORD}' + MYSQL_ALLOW_EMPTY_PASSWORD: 1 + volumes: + - 'sail-mysql:/var/lib/mysql' + - './vendor/laravel/sail/database/mysql/create-testing-database.sh:/docker-entrypoint-initdb.d/10-create-testing-database.sh' + networks: + - sail + healthcheck: + test: + - CMD + - mysqladmin + - ping + - '-p${DB_PASSWORD}' + retries: 3 + timeout: 5s +networks: + sail: + driver: bridge +volumes: + sail-mysql: + driver: local diff --git a/phpunit.xml b/phpunit.xml index 61c031c..c09b5bc 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -22,8 +22,7 @@ - - + From 100acf1d1fdc42df5160f778a5341ef8effd283c Mon Sep 17 00:00:00 2001 From: OrbisK Date: Tue, 20 May 2025 15:53:51 +0200 Subject: [PATCH 2/2] docs: update ssr readme command --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 557e4db..000565f 100644 --- a/README.md +++ b/README.md @@ -69,7 +69,7 @@ To start the development server, run: Open http://localhost in your browser. -To use SSR you need to run the following command in a separate terminal: +To test your SSR build you need to run the following commands: ```bash ./vendor/bin/sail pnpm build:ssr