PHP:Laravel 專案資料夾結構

Laravel 預設就將許多功能拆分在不同資料夾或檔案內
但是再依自己需求新增資料夾來符合單一功能原則也很 ok
以下將目前會使用到的 Laravel 和自己新增的資料夾做簡單描述

  • app
    • Http
      • Controllers:網站 controller 新增在此資料夾
      • Requests:處理 Controller 傳入參數驗證
    • Libraries:放共用程式
    • Presenters:跟 View 做搭配負責處理頁面上呈現邏輯
    • Providers:負責處理 Contrller 依賴注入要綁定的內容
    • Services:處理商業邏輯跟呼叫 API,通常是跟 Controller 做搭配
      • data:負責接收 API 傳回來的資料
  • config
    • develop:針對 development 環境中相關內容對應的值
    • production:針對 production 環境中相關內容對應的值
  • resources
    • views:存放 laravel blade 模板
  • routes
    • web.php:設定路徑對應 Controller
  • tests
    • Feature:針對完整功能做測試
    • Unit:針對單一 function 做測試
  • .env
    • 放資料庫等共用設定檔

results matching ""

    No results matching ""