---
# System prepended metadata

title: Composer

---

# Composer
### composer 初始化
~~~
composer init
~~~

使用上跟 flutter 更新蠻像的
修改 composer.json 把要用的模組寫在 require 區段裡
~~~
{
    "name": "laravel/laravel",
    "require": {
        "monolog/monolog": "^1.23"
    }
}
~~~

### 安裝 require 區段裡的模組
~~~
composer install
~~~
會產生 vendor 資料夾

### 自動讀取資料夾中寫好的 class
(如：資料夾名稱為 libraries)
~~~
{
    "name": "laravel/laravel",
    "require": {
        "monolog/monolog": "^1.23"
    },
    "autoload": {
        "classmap": [
            "libraries"
        ]
    }
}
~~~

1. 套用 composer.json 的修改或檔案新增
~~~
composer dump
~~~
會在 vendor 資料夾產生 autoload.php

2. 在進入頁面 require autoload.php 執行讀取
~~~
require 'vendor/autoload.php'
~~~