fredtux/artisan-view

通过Artisan管理Laravel项目的视图,并使用Bootstrap生成基于模型的CRUD视图

v3.6.0 2023-08-29 09:47 UTC

This package is auto-updated.

Last update: 2024-09-29 12:21:23 UTC


README

artisan-view

免责声明

这是一个https://github.com/svenluijten/artisan-view的分支版本,增加了使用Bootstrap生成基于模型的CRUD视图的功能。

Artisan View

Packagist上的最新版本 总下载量 软件许可证 [![构建状态][ico-build]][link-build] StyleCI

此包为Laravel项目中的Artisan添加了一些与视图相关的命令。生成扩展其他视图的blade文件,构建模板的各个部分,等等。所有这些都可以通过我们熟悉的命令行完成!

索引

安装

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

下载

通过composer

composer require fredtux/artisan-view --dev

注册服务提供者

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

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

public function register()
{
    if ($this->app->environment() !== 'production') {
        $this->app->register(\fredtux\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

生成视图(仅使用Bootstrap)

# Create a resource called 'products' with generated views using bootstrap ui extending layout.php
$ php artisan make:view products --resource --generate product --ui bootstrap --extends layout.php

# Create and generate edit and index views based on Product model using bootstrap ui extending layout.php
$ php artisan make:view products --verb=edit --verb=index --generate product --ui bootstrap --extends layout.php

抓取视图

# 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

贡献

所有贡献(以拉取请求、问题和功能请求的形式)都受到欢迎。有关所有贡献者的信息,请参阅贡献者页面

许可

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