MIT License

项目介绍

svenluijten/artisan-view 是一个托管在 GitHub 上的开源项目,主要使用 PHP 编写,采用 MIT License 许可证,目前获得 862 个 Star、107 次 Fork。

仓库全名
svenluijten/artisan-view
开源许可证
MIT License
Star 数
862
Fork 数
107

README 摘要

Artisan View This package adds a handful of view-related commands to Artisan in your Laravel project. Generate blade files that extend other views, scaffold out sections to add to those templates, and more. All from the command line we know and love! Installation You'll have to follow a couple of simple steps to install this package. Downloading Via composer: Registering the service provider Ensure…

完整内容见 GitHub 原始 README 或本页 。

常见问题

artisan-view 用什么语言开发?

主要使用 PHP 编写,采用 MIT License 许可证,目前有 862 个 Star。

artisan-view 可以免费商用吗?

仓库采用 MIT License 许可证,可免费使用与修改,商业使用请遵守许可证条款(例如保留版权声明与许可声明)。

如何获取 artisan-view 的源码?

可以直接克隆仓库:git clone https://github.com/svenluijten/artisan-view.git,默认分支为 3.x;安装与运行步骤见仓库 README。

artisan-view 最近还在维护吗?

仓库最近一次更新为 2023年9月15日,当前没有未关闭的 Issue;Star 数为 862,可作为社区活跃度的参考。

关于

👀 Manage your views in Laravel projects through artisan

描述取自 GitHub 官方 API,中文内容由 GitRead 中文社区 编辑团队整理。

简要分析

热度分
1077
价值分
549
活跃状态
归档

语言占比

PHP

Release

README

artisan-view

Artisan View

Latest Version on Packagist Total Downloads Software License Build Status StyleCI

This package adds a handful of view-related commands to Artisan in your Laravel project. Generate blade files that extend other views, scaffold out sections to add to those templates, and more. All from the command line we know and love!

Installation

You’ll have to follow a couple of simple steps to install this package.

Downloading

Via composer:

composer require sven/artisan-view --dev

Registering the service provider

Ensure Sven\ArtisanView\ServiceProvider::class is registered in the service container. For most people, this will have been done automatically thanks to auto-discovery. If you opted out of package auto-discovery, register it manually in one of your (non-deferred) service providers:

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

Alternatively, you can use sven/env-providers to only register Artisan View’s service provider in the development environment.

Usage

When running php artisan now, you will see two new commands in the list: make:view and scrap:view.

Creating a view

To create a single view file, invoke the make:view command with the desired view name as the first argument. The view can be nested by using dot.notation:

$ php artisan make:view dashboard # Creates 'dashboard.blade.php'
$ php artisan make:view users.create # Creates 'users/create.blade.php'

The file extension

This package defaults to using .blade.php as its file extension, but you may change that by specifying the --extension option:

$ php artisan make:view dashboard --extension=html.twig # Creates 'dashboard.html.twig'

Extending a view

If you want to pre-fill the generated view file with an @extends tag, use the --extends option:

$ php artisan make:view dashboard --extends=layouts.master
See result

dashboard.blade.php:

@extends('layouts.master')

Adding sections

To add sections to a view, you can use the --section option:

$ php artisan make:view posts.create --section=content
See result

posts/create.blade.php:

@section('content')

@endsection

You can even add inline sections (and pre-fill them) by using a colon (:) in the name of the section:

$ php artisan make:view posts.create --section=title:Awesome
$ php artisan make:view posts.edit --section="title:Edit the post" # Use quotes if you want to add spaces
See result

posts/create.blade.php:

@section('title', 'Awesome')

posts/edit.blade.php:

@section('title', 'Edit the post')

You can add multiple sections to the view by using the --section option multiple times:

$ php artisan make:view posts.show --section="title:Show an existing post" --section=content
See result

posts/show.blade.php:

@section('title', 'Show an existing post')

@section('content')

@endsection

Creating RESTful resources

You can use the make:view command to create 4 views (one for each logical RESTful verb) in one go. To do so, use the --resource option:

$ php artisan make:view posts --resource

This will create 4 views: posts/index.blade.php, posts/show.blade.php, posts/create.blade.php, and posts/edit.blade.php. This command can be used in combination with the other options described above.

You may want to only create a subset of the verbs. To do this, a --verb option is available. This is an array of names for the view to create:

$ php artisan make:view posts --resource --verb=index --verb=edit

This will only create 2 views: posts/index.blade.php and posts/edit.blade.php.

Scrapping a view

You may use the scrap:view command to remove one or more views from your project:

$ php artisan scrap:view index # Removes 'index.blade.php'
$ php artisan scrap:view posts.show # Removes 'posts/show.blade.php'

This will ask you for confirmation. If you are sure you want to remove the view, you can pass the --force flag:

$ php artisan scrap:view index --force # Do not ask for confirmation before removing 'index.blade.php'

Scrapping resources

Just like with make:view, you can use the --resource and --verb flags to scrap (parts of) a RESTful resource of views:

$ php artisan scrap:view posts --resource

This will remove index.blade.php, show.blade.php, edit.blade.php, and create.blade.php from posts/. If this directory is empty after deleting these views, it will also be removed.

You may wish to only remove part of a resource. You can do so with the --verb flag:

$ php artisan scrap:view posts --resource --verb=index --verb=show

This will remove posts/index.blade.php and posts/show.blade.php. If the posts/ directory is empty after deleting these views, it will also be deleted.

Contributing

All contributions (in the form on pull requests, issues and feature-requests) are welcome. See the contributors page for all contributors.

License

sven/artisan-view is licenced under the MIT License (MIT). Please see the license file for more information.

评论

暂无评论