sven/artisan-view

此包已被废弃,不再维护。作者建议使用 laravel/framework 包。

通过 Artisan 管理 Laravel 项目的视图

v3.6.1 2023-09-15 09:48 UTC

README

artisan-view

Artisan 视图

Latest Version on Packagist Total Downloads Software License Build Status StyleCI

警告
此包已被废弃。从 v10.23.0 版本开始,make:view 命令已成为 Laravel 的一部分,建议使用它。如果您使用的是 v10.23.0 之前的 Laravel 版本,仍然可以安装此包。

此包为您的 Laravel 项目中的 Artisan 添加了一些与视图相关的命令。生成扩展其他视图的 blade 文件,构建用于添加到模板的章节,等等。所有这一切都来自我们熟悉和喜爱的命令行!

索引

安装

您需要遵循几个简单的步骤来安装此包。

下载

通过 composer

composer require sven/artisan-view --dev

注册服务提供者

如果您使用的是 Laravel 5.5 或更高版本,可以跳过此步骤。服务提供者已经通过自动发现注册。

否则,请在 AppServiceProvider 的 register 方法中手动注册 Sven\ArtisanView\ServiceProvider::class

public function register()
{
    if ($this->app->environment() !== 'production') {
        $this->app->register(\Sven\ArtisanView\ServiceProvider::class);
    }    
}

使用

如果您现在运行 php artisan,您将看到列表中的两个新命令

  • make:view
  • scrap: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 --section="title:Hello world"

# 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.indexproducts.showproducts.createproducts.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.phpproducts/edit.blade.phpproducts/create.blade.phpproducts/show.blade.php

@extends('app')

@section('title', 'This is my title')

@section('content')

@endsection

贡献

欢迎所有贡献(包括通过拉取请求、问题和特性请求的形式)。查看所有贡献者的贡献者页面

许可证

sven/artisan-view 采用MIT许可证(MIT)授权。有关更多信息,请参阅许可证文件