Laravel 10 学習 Windows VS CODE サンプルアプリ チュートリアル #1

Laravel 10 学習 Windows VS CODE サンプルアプリ チュートリアル #1

Laravel10 サンプルアプリ作り Windows Laravel10 VS CODE Laravel拡張機能 環境構築

Laravel10 プロジェクト作成

今回の環境

windows 11

php -v
PHP 8.2.12 (cli) (built: Oct 24 2023 21:15:15) (ZTS Visual C++ 2019 x64)
Copyright (c) The PHP Group
Zend Engine v4.2.12, Copyright (c) Zend Technologies
    with Xdebug v3.3.2, Copyright (c) 2002-2024, by Derick Rethans

phpは、c:\xampp\php\ にあり、複数のバージョンを切り替えられるように設定済み。

環境変数path=…c:\xampp\php… が登録済。

composer --version
Xdebug: [Step Debug] Time-out connecting to debugging client, waited: 200 ms. Tried: localhost:9003 (through xdebug.client_host/xdebug.client_port).
Composer version 2.7.8 2024-08-22 15:28:36
PHP version 8.2.12 (C:\xampp\php\php.exe)
Run the "diagnose" command to get more detailed diagnostics output.

参考URL

https://laravel.com/docs/10.x

composer でLaravel10プロジェクト作成

composer create-project "laravel/laravel:^10.0" ideas

エラー発生時は、php.ini 設定を確認。

以下のようなエラー発生(色々)した場合は、php.iniの設定変更が必要です。

C:\work\dev>composer create-project "laravel/laravel:^10.0" ideas
Creating a "laravel/laravel:^10.0" project at "./ideas"
Installing laravel/laravel (v10.3.3)
  - Installing laravel/laravel (v10.3.3): Extracting archive
Created project in C:\work\dev\ideas
> @php -r "file_exists('.env') || copy('.env.example', '.env');"
Loading composer repositories with package information
Updating dependencies
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - Root composer.json requires spatie/laravel-ignition ^2.0 -> satisfiable by spatie/laravel-ignition[2.0.0, ..., 2.9.1].
    - spatie/laravel-ignition[2.0.0, ..., 2.9.1] require ext-curl * -> it is missing from your system. Install or enable PHP's curl extension.

To enable extensions, verify that they are enabled in your .ini files:
    - C:\work\xampp\php\php.ini
You can also run `php --ini` in a terminal to see which files are used by PHP in CLI mode.
Alternatively, you can run Composer with `--ignore-platform-req=ext-curl` to temporarily ignore these required extensions.

または、

C:\work\dev>composer create-project "laravel/laravel:^10.0" ideas
Creating a "laravel/laravel:^10.0" project at "./ideas"
Installing laravel/laravel (v10.3.3)
  - Installing laravel/laravel (v10.3.3): Extracting archive
Created project in C:\work\dev\ideas
> @php -r "file_exists('.env') || copy('.env.example', '.env');"
Loading composer repositories with package information
Updating dependencies
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - Root composer.json requires spatie/laravel-ignition ^2.0 -> satisfiable by spatie/laravel-ignition[2.0.0, ..., 2.9.1].
    - spatie/laravel-ignition[2.0.0, ..., 2.9.1] require ext-curl * -> it is missing from your system. Install or enable PHP's curl extension.

To enable extensions, verify that they are enabled in your .ini files:
    - C:\work\xampp\php\php.ini
You can also run `php --ini` in a terminal to see which files are used by PHP in CLI mode.
Alternatively, you can run Composer with `--ignore-platform-req=ext-curl` to temporarily ignore these required extensions.

C:\work\dev>composer update
Composer could not find a composer.json file in C:\work\dev
To initialize a project, please create a composer.json file. See https://getcomposer.org/basic-usage

ここでは、

c:\xampp\php\php.ini を以下のように修正。

;extension_dir = "ext" → extension_dir = "ext"

;extension=openssl → extension=openssl

;extension=fileinfo → extension=fileinfo

;extension=curl → extension=curl

そのあと、再度laravelプロジェクト作成を実行、

composer create-project "laravel/laravel:^10.0" ideas

以下のように …successully… でインストールは完了です。php バージョンやphp.iniによってエラーが出る場合があるようです。

インストール成功。laravelプロジェクトフォルダに移動し、

cd .\ideas

Laravel サーバーを起動、

php artisan serve

http://localhost:8000/

laravel10 インストール成功。今回は、PHPは8.1と8.2で試しました。問題なし。

今回作ったlaravelプロジェクト(ideasフォルダ)で、以下コマンドで VS CODE を起動する。

code .

Laravel開発で、VS CODE おすすめ拡張機能をインストールする

PHP Intelephense

PHP

Laravel Blade Snippets

Laravel Extension Pack

Tailwind CSS IntelliSense

Alpine.js IntelliSense

Livewire Language Support