javck
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    --- tags: laravel --- # 資料夾結構說明 ![](https://i.imgur.com/cxT4fSs.jpg) ## 簡介 預設的 Laravel 專案結構出發點是在為大型和小型應用提供一個良好的起點。但是你可以自由地組織你的應用資料夾結構。只要 Composer 可以自動加載類別,Laravel 幾乎不限制你將類別放在任何的位置(但你將為此付出設定變多,且維護難度提高的代價,這是官方文件沒說的事實) --- ## 專案根資料夾 ### App資料夾 app 資料夾存放你應用的核心程式碼。我們很快就會詳細地研究這個資料夾;不管怎樣,應用中幾乎所有的重要類別都將位於此資料夾 ### Bootstrap資料夾 bootstrap 資料夾包含了框架的啟動檔案 app.php 。該資料夾還包含 cache 目錄,其中包含用於提升框架性能的生成檔案,例如路由和服務快取檔案 ### Config資料夾 config 資料夾就如其名包含了應用的所有設定檔案。最好能把這些文件都瀏覽過一遍,並熟悉所有應用可用的選項 ### Database資料夾 database 資料夾包含資料庫的 Migration,模型工廠和 Seeder 文件。如果你想的話,也可以將之作為 SQLite 資料庫存放目錄 ### Public資料夾 public 資料夾包含 index.php 文件,它是所有請求進入應用的入口,用以配置自動加載。該資料夾還包含您的素材資源,如圖像、JavaScript 腳本和 CSS 樣式 ### Resource資料夾 resources 資料夾包含了視圖和未編譯的資源檔案(如 LESS、SASS 或 JavaScript)。此資料夾還包含你所有的本地化檔案 ### Route資料夾 routes 資料夾包含應用的所有路由定義。預設情況下,Laravel 包含幾個路由文件:web.php, api.php, console.php 以及 channels.php web.php 檔案包含 RouteServiceProvider 放置在 web 中介層群組的路由,這些中介層提供會話(Session)狀態、CSRF 保護和 cookie 加密。如果您的應用不需提供無狀態的 RESTful API,那麼您的所有路由都能夠放在 web.php 檔案內 api.php 檔案包含 RouteServiceProvider 放置在 api 中介層群組的路由,這些中介層提供速率限制。放在這個檔案內的這些路由應該是無狀態的,因此通過這些路由進入應用的請求將通過口令(Token)來進行身份驗證,並且不能訪問會話(Session)狀態 console.php 檔案是可用以定義所有基於閉包的控制台命令的地方。每個閉包都綁定到一個命令實例,允許使用一種簡單的方法與每個命令進行輸出入互動。儘管這個檔案沒有定義 HTTP 路由,但是它定義了應用中基於控制台的入口(路由),也就是命令相關的路由可放在這裡 channels.php 檔案是你可以註冊應用支持的所有事件廣播頻道的位置 ### Storage資料夾 storage 資料夾包含由 Blade 視圖框架生成的編譯檔案、以檔案形式儲存的會話(Session)內容和快取檔案。這個資料夾分成 app、framework 和 logs 目錄 app 資料夾可用於存放應用生成的任何檔案。framework 資料夾用於存放 laravel 框架生成的檔案和快取。最後,logs 目錄則包含應用的日誌文件 storage/app/public 資料夾用來存放用戶生成或上傳的檔案,例如使用者頭像,而它們應該是能夠被公開訪問的。為此,你需要創建一個指向到這個目錄的軟連結 public/storage (換言之,在 public 資料夾會有個 storage 捷徑,能跳轉到 storage/app/public 資料夾), 假如這個軟連結不存在,你可以通過這個命令 php artisan storage:link 來生成它 ### Tests資料夾 tests 資料夾包含自動化測試類別,這包含了範例單元測試與功能測試。每個測試類別都應該用單詞 Test 作為後綴。您可以使用 phpunit 或 php vendor/bin/phpunit 命令來運行測試。如果你想要更多完整資訊,並讓你的測試結果顯示得更為美觀,你可以透過 php artisan test 這樣的命令來運作你的測試 ### Vendor資料夾 vendor 資料夾包含你的 Composer 依賴,也就是所有下載的套件都被放在這個目錄之內 --- ## 專案App資料夾 應用的大部分程式碼都位於 app 目錄中。預設情況下,此目錄的名稱空間在 App 下(而非資料夾名稱app),並由 Composer 使用 PSR-4 標準來自動加載 app 資料夾包含各種目錄,如 Console、Http 和 Providers。可以將 Console 和 Http 資料夾看作是為應用的核心提供了一個 API。HTTP 協議和 CLI 都是與應用交互的機制,但實際上並不包含應用程式邏輯。換句話說,它們是向應用程序發出命令的兩種方式。Console 目錄包含所有 Artisan 命令,而 Http 目錄則包含控制器、中介層和請求 當使用 make 系列的 Artisan 命令生成類別時,將在 app 資料夾內生成各種目錄。例如當你執行 make:job 命令生成隊列類別時,將會生成 app/Jobs 資料夾 >技巧: > >app 目錄中的許多類別都可以由 Artisan 通過命令生成。要查看可用的命令,請在終端中運行 php artisan list make 命令,或者是運行 php artisan 也能夠看到所有的命令 ### Broadcasting資料夾 Broadcasting 資料夾包含應用的所有廣播頻道類別,這些類別都是通過 make:channel 命令生成的。這個目錄預設是不存在的,但是當你創建第一個廣播頻道類別時它會自動生成。要了解有關頻道的更多資訊,請查看 [廣播 BroadCasting](/2kYd80l_S7ei7XXGfR0xVw) ### Console資料夾 Console 資料夾包含應用所有自定義的 Artisan 命令, 這些類別通過 make:command 命令而生成。 此目錄也安置了控制台內核,在其中你可以註冊自定義的 Artisan 命令,並定義你的排程工作 ### Events資料夾 該資料夾預設是不存在的,但可以通過 event:generate 和 make:event 命令來創建。Events 目錄用於存放事件類別。事件類別用於告知應用其他部分某個事件的發生與情況並提供靈活的、解耦的處理機制 ### Exceptions資料夾 Exceptions 資料夾包含應用的異常處理器,同時還是處理應用拋出的任何異常的好地方。如果你想要自定義異常該如何記錄或渲染,就需要編輯該資料夾裏頭的 Handler 類別 ### Http資料夾 Http 資料夾包含了控制器、中介層以及表單請求等,幾乎所有通過 Web 路由進入應用的請求處理都在這裡進行,也可以說是入門時最常打交道的資料夾之一 ### Jobs資料夾 這個資料夾預設不存在,但可以通過執行 make:job 命令來生成,Jobs 目錄用於存放應用的隊列任務,應用中的任務可以被推送至隊列,也可以在當前請求生命周期內同步執行。同步執行的任務有時也被看作是命令,因為它們實現了命令模式(最後這句話有點微妙,我還沒能完全體會) ### Listeners資料夾 預設情況下此資料夾也不存在,但如果你執行 event:generate 或 make:listener Artisan 命令的話就會自動生成。Listeners 目錄包含所有處理事件的類別。在事件觸發後,事件偵聽器接收事件實例並執行處理邏輯。例如,UserRegistered 事件被 SendWelcomeEmail 監聽器所處理 ### Mail資料夾 預設情況下,此資料夾不存在,但如果你執行 make:mail Artisan 命令時就會自動生成。Mail 目錄包含應用所有代表被發送電子郵件的類別。Mail 對象允許你將構建電子郵件的所有邏輯封裝在一個簡單的類別中,而該類別可以使用 Mail::send() 進行發送 ### Models資料夾 Models 資料夾包含所有 Eloquent 模型類別,這也是在8.x所新增的資料夾,在之前版本所有的模型是直接放在 app 資料夾內。Laravel 附帶的 Eloquent ORM 為處理資料庫提供了一個漂亮、簡單的 ActiveRecord 實作。每個資料庫表格都有一個對應的「模型」,用於與該表格進行交互。模型能協助你查詢表格中的數據,以及向表格寫入新記錄 ### Notifications資料夾 預設情況下,此資料夾不存在,但如果你執行 make:notification Artisan 命令時會自動生成。Notifications 資料夾包含所有被你的應用所發送的「事務性」通知,例如關於應用內所發生事件的簡單通知。Laravel 的通知功能抽象了通過各種驅動發送的通知,如電子郵件通知、Slack 資訊、SMS 短信通知或資料庫存儲 ### Policies資料夾 預設情況下,此資料夾不存在,但如果執行 make:policy Artisan 命令就會生成。Policies 目錄包含應用的授權邏輯類別。這些類用於確認用戶是否可以對資源執行某種的操作。如需更多相關資料,請查看 [授權 Authorization](/bQ0d8X-nTLKVdTKyZGw4lQ) ### Providers資料夾 Providers 資料夾包含應用中所有的服務供應器。服務供應器通過在服務容器中綁定服務、註冊事件或執行任何其他任務來引導應用以準備好應對將傳入的請求 在一個新的 Laravel 應用中,這個資料夾已經包含了幾個供應器。您可以根據需要將自己的供應器加入此資料夾 ### Rules資料夾 預設情況下,此資料夾不存在,但如果執行 make:rule Artisan 命令後就會生成。Rules 資料夾包含應用內自定義的驗證規則。這些驗證規則用於將複雜的驗證邏輯封裝在一個簡單的對象中。有關更多信息,請查看 [Form and Validation](/O6PetMaXQr-BNdhBbvzZfQ) --- ## 參考資料 ![](https://i.imgur.com/iZJjEeP.png)

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully