Skip to content

feat: Laravel 12 quickstart with tests#7028

Merged
rfay merged 5 commits into
ddev:mainfrom
stasadev:20250227_stasadev_laravel_12
Mar 5, 2025
Merged

feat: Laravel 12 quickstart with tests#7028
rfay merged 5 commits into
ddev:mainfrom
stasadev:20250227_stasadev_laravel_12

Conversation

@stasadev

@stasadev stasadev commented Feb 27, 2025

Copy link
Copy Markdown
Member

The Issue

Laravel 12 was released https://laravel.com/docs/12.x/releases

How This PR Solves The Issue

  • Updates quickstart to use Laravel 12
  • Adds a dedicated SQLite quickstart for Laravel
  • Updates Laravel Installer to make it clearer
  • Adds Laravel quickstart tests

Manual Testing Instructions

https://ddev--7028.org.readthedocs.build/en/7028/users/quickstart/#laravel

Automated Testing Overview

Release/Deployment Notes

@stasadev stasadev requested review from a team as code owners February 27, 2025 10:25
@github-actions

github-actions Bot commented Feb 27, 2025

Copy link
Copy Markdown

@stasadev stasadev requested a review from tyler36 February 27, 2025 10:32

@rfay rfay left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks to me like it's just what we need! Thanks!

@tyler36 tyler36 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the update!

Comment thread docs/content/users/quickstart.md Outdated
DDEV defaults to using a MariaDB database to better represent a production environment.

To select the [Laravel 11 defaults](https://laravel.com/docs/11.x/releases#application-defaults) for SQLite, use this command for `ddev config`:
To select the [Laravel defaults](https://laravel.com/docs/11.x/releases#application-defaults) for SQLite, use this command for `ddev config`:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
To select the [Laravel defaults](https://laravel.com/docs/11.x/releases#application-defaults) for SQLite, use this command for `ddev config`:
To use a SQLite database when creating a new project, replace the `ddev config` command with the following instead:

This removes the link, which is a moving target.

Comment thread docs/content/users/quickstart.md Outdated
Comment on lines 550 to 583
!!!tip "Want to use a SQLite database for Laravel?"
DDEV defaults to using a MariaDB database to better represent a production environment.

To select the [Laravel 11 defaults](https://laravel.com/docs/11.x/releases#application-defaults) for SQLite, use this command for `ddev config`:
To select the [Laravel defaults](https://laravel.com/docs/11.x/releases#application-defaults) for SQLite, use this command for `ddev config`:
```bash
ddev config --project-type=laravel --docroot=public --omit-containers=db --disable-settings-management=true
```

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A problem with this section is that only applies when starting a new project.
For existing projects you need to:

  • update .env to DB_CONNECTION="sqlite"
ddev config --project-type=laravel --docroot=public --omit-containers=db --disable-settings-management=true
ddev restart
ddev artisan migrate:fresh

If you don't update the .env you will get the following error (included for searchability):

SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo for db failed: Name or service not known (Connection: mariadb, SQL: select * from `sessions` where `id` = jvwGaqOpdMyrsUZa412ljRqpuaNOIqPSw2NJE2XN limit 1)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch!

I think we should put the SQLite config on a separate tab, where we mention how to migrate from one to the other.

If we add everything on one tab, it will complicate things for newcomers.

@rpkoller rpkoller left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good (tested the composer and laravel isntaller steps), i left one comment on the tests and two observations about applying the laravel installer quickstart:

  1. i am not sure if i have tested the laravel installer before, but somehow i only copy and pasted the echo line echo 'ARG COMPOSER_HOME=/usr/local/composer then thought i'Ve missed the single quote, after another try it dawned to me that it is a single command. for readability the current version is definitely better but it could be misleading like in my case. therefore i wonder if putting it in a single line would be the more clear choice?

  2. for ddev exec laravel new temp --database=sqlite would it make sense to add to the comment before the commant, that the the user should follow the defaults none and for picking no starterkit to install and yes for running the npm build?

Comment thread docs/tests/laravel.bats

run curl -sf https://${PROJNAME}.ddev.site
assert_success
assert_output --partial "Laravel"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if it would make sense to slightly extend the assertion and use <title>Laravel</title>instead? would be still prone to potential updates but still more specific than just Laravel? (if so it would have to be applied to line 127 as well)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if it would make sense to slightly extend the assertion and use <title>Laravel</title>instead?

If the database setting are incorrectly set by DDEV, the resulting error page contains the word "Laravel" and the header "<title>Laravel</title>".

image

If I recall, there were some shenanigans with collation settings and Laravel 11. Would the tests have caught that issue?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i just manually tested and changed the DB_HOST from db to dbs in the .env file. after that curl -sf https://lari.ddev.site returns nothing so i suppose the assertion would fail in that case

@rpkoller rpkoller Feb 28, 2025

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

curl -sf https://lari.ddev.site returns nothing while curl -sfI https://lari.ddev.sitereturns:

HTTP/2 500 
cache-control: no-cache, private
content-type: text/html; charset=UTF-8
date: Fri, 28 Feb 2025 04:20:43 GMT
server: nginx

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, so it would be caught by assert_output --partial "HTTP/2 200" then.
Thank you for checking.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep, even both assertions would fail. neither the 200 nor the Laravel one would pass.

@stasadev

stasadev commented Feb 28, 2025

Copy link
Copy Markdown
Member Author

therefore i wonder if putting it in a single line would be the more clear choice?

@rpkoller, I think it was the syntax highlighting that confused you.

I'll replace it with cat <<'DOCKERFILEEND' like it's done for FrankenPHP.

for ddev exec laravel new temp --database=sqlite would it make sense to add to the comment before the commant, that the the user should follow the defaults none and for picking no starterkit to install and yes for running the npm build?

If people use Laravel Installer, it usually means that they want to use StarterKit. I will make the comment clearer about the choice, thank you!

@stasadev stasadev force-pushed the 20250227_stasadev_laravel_12 branch from 5198bd3 to 31ab5c9 Compare February 28, 2025 13:43
@stasadev

Copy link
Copy Markdown
Member Author

I updated Laravel Quickstart with Composer (SQLite) and made some small changes to Laravel Installer.

@stasadev stasadev requested review from rpkoller and tyler36 February 28, 2025 13:46
@stasadev stasadev force-pushed the 20250227_stasadev_laravel_12 branch from 0c8835a to 98b4be5 Compare February 28, 2025 14:32
Comment on lines +524 to +526
ddev composer run-script post-root-package-install
ddev dotenv set .env --db-connection=sqlite
ddev composer run-script post-create-project-cmd

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

post-root-package-install copies .env.example to .env if it doesn't exist, then we set the sqlite connection in .env, and finally run migrations in post-create-project-cmd.

@tyler36 tyler36 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good.

I was able to create a project with the "default" mariadb database, then convert to Sqlite database.

Thank you!

@rpkoller rpkoller left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for the changes. the syntax highlighting makes it way clearer now and the comment i've raised looks good now as well. and i've ran through the two tests another time and all worked well. added only one more comment about one small stumbling block i havent noticed in the previous review.

@@ -507,28 +533,37 @@ The Laravel project type can be used for [StarterKits](https://laravel.com/docs/
mkdir my-laravel-site && cd my-laravel-site
ddev config --project-type=laravel --docroot=public

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is only one minor nitpick about a detail i've just noticed. line 536 refers to line 534 stating that it is using mariadb, while line 538 uses sqlite instead. the detail i dont understand, with the active default you set the project up for mariadb but in line 553 sqlite is used anyway? that is not entirely clear to me why you use mariadb and sqlite alongside?

and in general the comment in 536 is hard to comprehend cuz it requires that you jump in-between lines referring to the lines before and after the comment. Plus if the quickstart states "This config uses.." strictly speaking me as the recipient would expect that line 538 would set up mariadb. how about something like the following instead?

# To use MariaDB apply the following command
ddev config --project-type=laravel --docroot=public

# To use SQLite, uncomment and use the following command instead
#ddev config --omit-containers=db --disable-settings-management=true

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but in line 553 sqlite is used anyway?

It's because if you specify a different database (other than SQLite) at this point, the database migrations will fail, which would cause more confusion. You can try it with:

ddev exec laravel new temp
ddev exec laravel new temp --database=mariadb

I don’t have access to alter the .env content when running laravel new.

I tried to make the comment for ddev exec laravel new temp --database=sqlite a bit clearer.

how about something like the following instead?
# To use SQLite, uncomment and use the following command instead

Good idea! I think it's better to add --project-type=laravel --docroot=public in this case when we say "instead".

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah thanks for the explanation. i like the improvements you made to the comment! and yep i also agree adding --project-type=laravel --docroot=public. looks good, thank you!

@rfay rfay merged commit 623b9bf into ddev:main Mar 5, 2025
@rfay rfay deleted the 20250227_stasadev_laravel_12 branch March 5, 2025 17:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants