syofyanzuhad / artisan-view
通过Artisan在Laravel项目中管理视图
Requires
- php: ^7.1 || ^8.0
- laravel/framework: ^5.4 || ^6.0 || ^7.0 || ^8.0
Requires (Dev)
- graham-campbell/testbench: ^4.0 || ^5.0
- mockery/mockery: ^1.4
- phpunit/phpunit: ^6.5 || ^7.0 || ^8.0
- 3.x-dev
- v3.4.0
- v3.3.2
- v3.3.1
- v3.3.0
- v3.2.0
- v3.1.0
- 3.0.x-dev
- v3.0.1
- v3.0.0
- v2.1.0
- 2.0.x-dev
- 2.0.3
- 2.0.2
- 2.0.1
- 2.0.0
- 2.0.0-beta3
- 2.0.0-beta2
- 2.0.0-beta1
- v1.3.4
- 1.3.3
- 1.3.2
- 1.3.1
- 1.3.0
- 1.2.3
- 1.2.2
- 1.2.1
- 1.2.0
- 1.1.2
- 1.1.1
- 1.1.0
- 1.0.x-dev
- 1.0.1
- 1.0.0
- 0.0.1
- dev-feature/fill-section
- dev-feature/inline-section-and-fill-section
- dev-main
- dev-update-workflow
This package is auto-updated.
Last update: 2024-09-04 20:39:44 UTC
README
Artisan View
此包向Laravel项目中的Artisan添加了一些与视图相关的命令。生成扩展其他视图的blade文件,为模板添加部分,等等。一切都可以通过我们熟悉的命令行操作完成!
索引
安装
您需要按照以下简单步骤安装此包。
下载
通过 composer
$ composer require syofyanzuhad/artisan-view --dev
注册服务提供者
如果您使用的是Laravel 5.5或更高版本,可以跳过此步骤。由于自动发现,服务提供者已经注册。
否则,请手动在 AppServiceProvider 的 register 方法中注册 Syofyanzuhad\ArtisanView\ServiceProvider::class
public function register() { if ($this->app->environment() !== 'production') { $this->app->register(\Syofyanzuhad\ArtisanView\ServiceProvider::class); } }
使用
如果您现在运行 php artisan,您将在列表中看到两个新命令
make:viewscrap:view
创建视图
# Create a view 'index.blade.php' in the default directory $ php artisan make:view index # Create a view 'index.blade.php' in a subdirectory ('pages') $ php artisan make:view pages.index # Create a view with a different file extension ('index.html') $ php artisan make:view index --extension=html
扩展和部分
# Extend an existing view $ php artisan make:view index --extends=app # Add a section to the view $ php artisan make:view index --section=content # Add multiple sections to the view $ php artisan make:view index --section=title --section=content # Add an inline section to the view # Remember to add quotes around the section if you want to use spaces $ php artisan make:view index --inline-section="title:Hello world" # Add a section to the view and fill it # Remember to add quotes around the section if you want to use spaces $ php artisan make:view index --section="content:<some-html-tag></some-html-tag>" # Create sections for each @yield statement in the extended view $ php artisan make:view index --extends=app --with-yields # Add @push directives for each @stack statement in the extended view $ php artisan make:view index --extends=app --with-stacks
REST资源
# Create a resource called 'products' $ php artisan make:view products --resource # Create a resource with only specific verbs $ php artisan make:view products --resource --verb=index --verb=create --verb=edit
抓取视图
# Remove the view 'index.blade.php' $ php artisan scrap:view index # Remove the view by dot notation $ php artisan scrap:view pages.index
这将询问您是否确定。要跳过此问题,请传递 --force 标志
# Don't ask for confirmation
$ php artisan scrap:view index --force
抓取REST资源
# Remove the resource called 'products'
$ php artisan scrap:view products --resource
这将删除视图 products.index、products.show、products.create 和 products.edit。如果执行此操作后目录 products/ 为空,它也将被删除。
您可以通过添加 --verb 标志来部分抓取资源
# Remove the 'products.create' and 'products.edit' views.
$ php artisan scrap:view products --resource --verb=create --verb=edit
混合匹配
当然,所有选项都可以像您预期的那样很好地一起工作。因此,以下命令...
$ php artisan make:view products --resource --extends=app --section="title:This is my title" --section=content
... 将以下内容放入 products/index.blade.php、products/edit.blade.php、products/create.blade.php 和 products/show.blade.php
@extends('app') @section('title', 'This is my title') @section('content') @endsection
贡献
所有贡献(以拉取请求、问题和功能请求的形式)都受到欢迎。请参阅贡献者页面以了解所有贡献者。
许可证
syofyanzuhad/artisan-view 采用MIT许可证(MIT)许可。有关更多信息,请参阅许可证文件。
