在 Laravel 中通過 Artisan View 擴充包建立及刪除應用視圖檔案

來源:互聯網
上載者:User

1、簡介

本擴充包添加了兩個視圖相關的Artisan命令到Laravel應用,以便我們通過Artisan命令即可建立和管理檢視檔案,可謂是進一步解放了生產力。

2、安裝

還是通過Composer安裝:

composer require sven/artisan-view

安裝完成後到 config/app.php 中註冊服務提供者 ArtisanViewServiceProvider 到 providers 數組:

// config/app.php'providers' => [    ...    Sven\ArtisanView\ArtisanViewServiceProvider::class,];

3、使用

如果你現在運行 php artisan 會發現多出如下兩個命令,分別用於建立和刪除視圖檔案:

- make:view- scrap:view

建立視圖

# 在視圖根目錄'views'下建立'index.blade.php'視圖檔案$ php artisan make:view index# 在子目錄'pages’下建立'index.blade.php'視圖檔案$ php artisan make:view pages.index# 在自訂目錄(相對於系統根目錄)下建立視圖檔案$ php artisan make:view index --directory=custom/path# 指定視圖副檔名$ php artisan make:view index --extension=html# 繼承一個已存在的視圖$ php artisan make:view index --extends=app# 在視圖中添加title和content部分$ php artisan make:view index --sections=title,content# 建立一個名為products的資源(包含index、create、edit、show視圖檔案)$ php artisan make:view products --resource# 建立指定動作資源(index、create和edit)$ php artisan make:view products --resource --verbs=index,create,edit# 建立繼承自layout且包含foo、bar的資源檔$ php artisan make:view products --resource --extends=layout --sections=foo,bar

刪除視圖

# 刪除視圖檔案 'index.blade.php'$ php artisan scrap:view index# 通過.刪除子目錄視圖檔案$ php artisan scrap:view pages.index
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.