👀 Manage your views in Laravel projects through artisan

Overview

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!

Index

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

If you're using Laravel 5.5 or above, you can skip this step. The service provider will have already been registered thanks to auto-discovery.

Otherwise, register Sven\ArtisanView\ServiceProvider::class manually in your AppServiceProvider's register method:

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

Usage

If you now run php artisan you will see two new commands in the list:

  • make:view
  • scrap:view

Creating views

# 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

Extending and sections

# 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 resources

# 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

Scrapping views

# Remove the view 'index.blade.php'
$ php artisan scrap:view index

# Remove the view by dot notation
$ php artisan scrap:view pages.index

This will ask you if you're sure. To skip this question, pass the --force flag:

# Don't ask for confirmation
$ php artisan scrap:view index --force

Scrapping a REST resource

# Remove the resource called 'products'
$ php artisan scrap:view products --resource

This will remove the views products.index, products.show, products.create, and products.edit. If the directory products/ is empty after doing that, it will also be deleted.

You can scrap part of a resource by adding --verb flags:

# Remove the 'products.create' and 'products.edit' views.
$ php artisan scrap:view products --resource --verb=create --verb=edit

Mix and match

Of course, all the options work well together like you'd expect. So the following command...

$ php artisan make:view products --resource --extends=app --section="title:This is my title" --section=content

... will put the following contents in products/index.blade.php, products/edit.blade.php, products/create.blade.php, and products/show.blade.php:

@extends('app')

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

@section('content')

@endsection

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.

Comments
  • How about a --clone directive

    How about a --clone directive

    Being able to clone existing views, then making minor changes to them would be sweet. Currently, we just copy and paste code from one view to the other and modify that.

    opened by webstractions 9
  • New feature to parse @yield directives from extended parent view

    New feature to parse @yield directives from extended parent view

    In conjunction with --extends, parse the parent view for all @yield directives and inject into the created view. You can do this automatically without another --directive, or not.

    This is similar to another make:view github project at maddhatter/laravel-view-generator.

    This would simplify things quite a bit. Having to add a --section or even --sections to every make command is a little tedious. Having the @sections ready to go in the created file is a big time saver. And if you don't need them, heck, it's easier to delete than copy/paste or typing it all over again.

    opened by webstractions 7
  • Error When Trying to Generate View

    Error When Trying to Generate View

    I installed this package in a fresh lareval 5.5 project, however when I try to actually use it to generate a view I get the following error

    error

    I have tried using it with and without registering '\Sven\ArtisanView\ServiceProvider::class' in my service provider class.

    Any clues as to why it would not work?

    bug 
    opened by adriangordon1231 6
  • Update ArtisanViewServiceProvider.php

    Update ArtisanViewServiceProvider.php

    shared & bindShared should be replaceable by call to app->singleton. But since it's only commands getting registered, then making it a deferred ServiceProvider shouldn't be an issue. :)

    opened by sasin91 5
  • can i fill the the content section

    can i fill the the content section

    i just try to fill the content section with many html like this : image

    but its return an error : image

    and this is my entire of content section :

    is there any solution ?

    <body style="margin-bottom: 29px;">
       
       <img src="https://api.pondokprogrammer.com/img/sertifikat/sertifikat-2.png" alt="" width="100%" id="background" style="position: absolute; z-index: -1">
       <div class="background pt-2 mt-5">
          <div class="my-5 p-auto" style="margin: 2%; padding: 0px; text-align:center; ">
             
             <div class="container" style="z-index: 0; position: absolute">
                <div class="row" style="display: flex; justify-content: center">
                   <div style="margin-left: 115.7%; margin-top: 2%">
                      <img style="margin-top: 18%; margin-right: 110%;" width="100" src="https://api.pondokprogrammer.com/img/pondok-programmer.png" alt="logo">
                   </div>
                   <div style="margin-left: 15%; width: 200%">
                      <h1 style="margin-right: 50%; z-index: 0; position: absolute" class="font-weight-bold mt-3">CERTIFICATE OF COMPLETION</h1>
                   </div>
                </div>
             </div>
             <div style="margin-top: 20%">
                <div style="text-align: left; margin-left: 10%">
                   <span style="font-size:25px"><i>This is to certify that</i></span>
                   <br>
                   <span style="font-size:40px"><b>Syofyan Zuhad</b></span><br>
                   <span style="font-size:25px"><i>has completed the study at</i> <span class="text-info">Pondok Programmer</span><i> in </i>:</span> <br><br>
                   <span style="font-size:30px" class="text-info">Laravel Backend Development</span> <br>
                   <span style="font-size:20px">with score of <span class="text-info font-weight-bold display-4">A+</span></span> 
                   <br><br>
                </div>
                   <table align="center" class="table text-center mt-3" style="border: none !important;">
                      <tbody><tr>
                         <td>
                            <span style="font-size:20px"><i>Syofyan Zuhad <small class="text-muted">- Mentor Backend</small></i></span><br><br><br><br>
                         </td> 
                         <td>
                            
                         </td>
                         <td>
                            <span style="font-size:20px"><i>Hafif Albusyro <small class="text-muted">- Chief</small></i></span><br><br><br><br>
                         </td>
                      </tr>
                      <tr>
                         <td>
                            Thursday, 
                            <span style="font-size:20px">01 April 2021</span>
                         </td>
                         <td width="10px">
                            <div style="margin-top: -20%; padding: 0px">
                               <img width="100" src="https://chart.googleapis.com/chart?cht=qr&amp;chs=130x130&amp;chl=https://api.pondokprogrammer.com/certificate/TuhWmpBLG&amp;choe=UTF-8" alt="qr">
                            </div>
                         </td>
                         <td>
                            Thursday, 
                            <span style="font-size:20px">01 April 2021</span>
                         </td>
                      </tr>
                   </tbody></table>
                </div>
             </div>
          </div>
       
    </body>
    
    opened by syofyanzuhad 4
  • Lumen support

    Lumen support

    Hi! Would it be possible to have support for the Lumen framework?

    Currently, it is possible to require this package in a Lumen project. The problem is, it requires the entire laravel/framework as a dependency. This breaks composer if some illuminate/* package is also required.

    For example, i required illuminate/mail to have mailing functionality in my project. If i then try to install this package, sometimes composer breaks up, other times it lets me install it. But even the few times it installs, other things break. An example:

    PHP Fatal error:  Uncaught ReflectionException: Class path.storage does not exist in A:\projects\_tmp\lumen\vendor\laravel\framework\src\Illuminate\Container\Container.php:805
    Stack trace:
    #0 A:\projects\_tmp\lumen\vendor\laravel\framework\src\Illuminate\Container\Container.php(805): ReflectionClass->__construct('path.storage')
    #1 A:\projects\_tmp\lumen\vendor\laravel\framework\src\Illuminate\Container\Container.php(687): Illuminate\Container\Container->build('path.storage')
    #2 A:\projects\_tmp\lumen\vendor\laravel\framework\src\Illuminate\Container\Container.php(633): Illuminate\Container\Container->resolve('path.storage', Array)
    #3 A:\projects\_tmp\lumen\vendor\laravel\lumen-framework\src\Application.php(267): Illuminate\Container\Container->make('path.storage', Array)
    #4 A:\projects\_tmp\lumen\vendor\laravel\framework\src\Illuminate\Foundation\helpers.php(119): Laravel\Lumen\Application->make('path.storage', Array)
    #5 A:\projects\_tmp\lumen\vendor\laravel\framework\src\Illuminate\Foundation\helpers.php(832): app('path.stora in A:\projects\_tmp\lumen\vendor\laravel\framework\src\Illuminate\Container\Container.php on line 807
    
    Fatal error: Uncaught ReflectionException: Class path.storage does not exist in A:\projects\_tmp\lumen\vendor\laravel\framework\src\Illuminate\Container\Container.php on line 807
    
    Illuminate\Contracts\Container\BindingResolutionException: Target class [path.storage] does not exist. in A:\projects\_tmp\lumen\vendor\laravel\framework\src\Illuminate\Container\Container.php on line 807
    
    ...
    

    It seems like this mess happens whenever a package has the entire Laravel framework as a dependency: laravel/lumen-framework/issues/870#issuecomment-516780947 (see also laravel/lumen-framework#798 , laravel/lumen-framework#504).

    So, i'm asking if it would be possible to include just the bare necessary illuminate, symfony, ecc submodules instead of the entire framework, so that it would work even with Lumen. As an example, check out flipbox/lumen-generator's requires.


    Thank you for your time, Have a nice day

    opened by aetonsi 4
  • Can not create view

    Can not create view

    Hello Seven, I'm newbie Laravel, after I installed artisan-view add registered services provider I run command bellow. Then Exception throw. Please help me!! Thanks Seven a lot. C:\xampp7\htdocs\sample-project>php artisan make:view settings.edit

    [Symfony\Component\Debug\Exception\FatalThrowableError] Type error: Argument 1 passed to Sven\ArtisanView\ViewActor::getViewNames() must be an instance of Sven\ArtisanView\iterable, array given, called in C:\xampp7\htdocs\sample-proj ect\vendor\sven\artisan-view\src\Generator.php on line 17

    opened by vuuvinhphuc 4
  • does that package implement the method in a specified controller?

    does that package implement the method in a specified controller?

    My idea, when i found this article, which lead me to here, was I was hoping to see if artisan had a way to generate a view, and add a method which returns that view, in one swoop, to an existing controller, which is specified. I was surprised when i came here, this package either doesn't do that, or I cant find that info in the readme. Im not normally one to dig through packages to find features, I feel they should be prominently displayed on the readme.

    Does this have that that feature, or does someone know if a package that does? That's the only way I can see justifying the need to generate a view.

    Thanks!

    opened by brian-lamb-software-engineer 4
  • Laravel upgrade to 5.4

    Laravel upgrade to 5.4

    Can't upgrade Laravel to 5.4 Call to undefined method Illuminate\Foundation\Application::share() As of laravel 5.4 share has been removed. You will have to use the singleton instead.

    opened by ghost 4
  • Scrapping the last view in a directory should remove the directory

    Scrapping the last view in a directory should remove the directory

    Assume the following views:

    views
    └─ products
       │ index.blade.php
    

    When executing php artisan scrap:view products.index, it keeps the folder products. Since index.blade.php is the last view in that folder, it should remove the folder as well.

    enhancement 
    opened by svenluijten 3
  • Extending this package to inject content into view

    Extending this package to inject content into view

    I would like to use this package to create views, however, I would like to create my own logic on how to put content dynamically inside that view.

    I couldn't find how this package can put blade content inside view. But if I'd like to implement my own code, how can I inject my output inside the view created by this package?

    Thanks, and great work BTW!

    opened by ilmam 2
  • New feature create views from Stub files

    New feature create views from Stub files

    Hello

    i want recommend add new feature for excellent Artisan-View

    create views from Stub files generate

    for example normally is same data only change few parameters inside of each file

    i see this project https://medium.com/@devlob/laravel-crud-generators-614caddf8bea

    i think can be done same way from Artisan-View for add it

    $model $url $route

    _form.stub
    create.stub
    edit.stub
    index.stub
    show.stub

    div> @include('brands._form',[ 'url'=>route('brands.show',$model->id), 'readonly'=>true, ])

    Thanks

    Best Regard

    fjmpchato

    opened by fjmpchato 2
  • Create view copying all the content

    Create view copying all the content

    Hi!

    I would like to ask you to implement the tag --duplicate. This would help me to copy all the content from a view just changing the filename and the references inside it.

    Cheers.

    enhancement 
    opened by lflucasferreira 2
  • Add support for wildcard characters when removing a view

    Add support for wildcard characters when removing a view

    php artisan scrap:view folder.* --force should remove all views in folder/. The wildcard character can only be used at the end of the argument, and will only work for removing files, not folders. So using php artisan scrap:view posts.*.index would not work in a situation like this:

    posts/
    |-authors/
    | | index.blade.php
    | | show.blade.php
    --comments/
      | index.blade.php
      | show.blade.php
    

    With the above situation, php artisan scrap:view posts.* would only remove the top-level files in the posts/ folder, the authors/ and comments/ folders (or files in them) will not be affected.

    enhancement 
    opened by svenluijten 0
  • Add default configuration

    Add default configuration

    I want to apply some options to all the views I create unless I say the opposite, like extending a certain layout or having certain elements. This could be archieved by adding a config file.

    enhancement 
    opened by m1guelpf 11
  • Releases(v3.5.0)
    Owner
    Sven Luijten
    I build stuff for the web.
    Sven Luijten
    📝 Artisan Menu - Use Artisan via an elegant console GUI

    ?? Artisan Menu Use Artisan via an elegant console GUI Features Run built-in and custom Artisan commands from a console GUI Prompts to enter required

    Jordan Hall 149 Dec 29, 2022
    📝 Artisan Menu - Use Artisan via an elegant console GUI

    ?? Artisan Menu Use Artisan via an elegant console GUI Features Run built-in and custom Artisan commands from a console GUI Prompts to enter required

    Jordan Hall 148 Nov 29, 2022
    🧑‍🔬 The missing assertions for your views in your Laravel applications.

    Laravel View Assertions The missing assertions for your views in your Laravel applications. Installation You'll have to follow a couple of simple step

    Sven Luijten 4 Dec 21, 2022
    Easily add a full Laravel blog (with built in admin panel and public views) to your laravel project with this simple package.

    Webdevetc BlogEtc - Complete Laravel Blog Package Quickly add a blog with admin panel to your existing Laravel project. It has everything included (ro

    WebDevEtc. 227 Dec 25, 2022
    A package to easily make use of Iconic icons in your Laravel Blade views.

    Blade Iconic A package to easily make use of Iconic icons in your Laravel Blade views. For a full list of available icons see the SVG directory. Iconi

    Malik Alleyne-Jones 17 Aug 25, 2022
    A package to easily make use of Simple Icons in your Laravel Blade views.

    Blade Simple Icons A package to easily make use of Simple Icons in your Laravel Blade views. For a full list of available icons see the SVG directory.

    UB Labs 12 Jan 17, 2022
    Cagilo - a set of simple components for use in your views Laravel Blade.

    Cagilo - a set of simple components for use in your views Laravel Blade. Official Documentation Documentation for Cagilo can be found on its we

    Cagilo 151 Dec 6, 2022
    Take a look into your Laravel views

    Xray - Take a look into your Laravel views When your Laravel project grows, so do the Laravel views. Sometimes it might be hard to figure out, which p

    Beyond Code 572 Aug 6, 2022
    A package to easily make use of SVG icons in your Laravel Blade views.

    Blade Icons A package to easily make use of SVG icons in your Laravel Blade views. Originally "Blade SVG" by Adam Wathan. Turn... <!-- camera.svg -->

    Blade UI Kit 1.7k Jan 2, 2023
    Blade UI Kit is a set of renderless components to utilise in your Laravel Blade views

    Blade UI Kit is a set of renderless components to utilise in your Laravel Blade views. In all essence, it's a collection of useful utilities, connecting the dots between different parts of the TALL stack. It was made for Blade, Laravel's powerful templating engine.

    Blade UI Kit 1.2k Jan 5, 2023
    A package to easily make use of Iconsax in your Laravel Blade views.

    Blade Iconsax A package to easily make use of Iconsax in your Laravel Blade views. This package contains 1.000 icons in 6 diferent styles, a total of

    Guilherme Saade 4 Oct 22, 2022
    A package that uses blade templates to control how markdown is converted to HTML inside Laravel, as well as providing support for markdown files to Laravel views.

    Install Install via composer. $ composer require olliecodes/laravel-etched-blade Once installed you'll want to publish the config. $ php artisan vendo

    Ollie Codes 19 Jul 5, 2021
    Stash view is a composer package for Laravel which caches views using Russian Doll Caching methodology.

    Stash View Stash view is a composer package for Laravel which caches views using Russian Doll Caching methodology. What is Russian Doll Caching ? It i

    Bhushan Gaikwad 18 Nov 20, 2022
    Slim Framework custom views

    Slim Views This repository contains custom View classes for the template frameworks listed below. You can use any of these custom View classes by eith

    Slim Framework 308 Nov 7, 2022
    Llum illuminates your Laravel projects speeding up your Github/Laravel development workflow

    Llum illuminates your Laravel projects speeding up your Github/Laravel development workflow

    Sergi Tur Badenas 110 Dec 25, 2022
    Laravel-OvalFi helps you Set up, test, and manage your OvalFi integration directly in your Laravel App.

    OvalFi Laravel Package Laravel-OvalFi helps you Set up, test, and manage your OvalFi integration directly in your Laravel App. Installation You can in

    Paul Adams 2 Sep 8, 2022
    A package that makes it easy to have the `artisan make:` commands open the newly created file in your editor of choice.

    Open On Make A package that makes it easy to have the artisan make: commands open the newly created file in your editor of choice. Installation compos

    Andrew Huggins 94 Nov 22, 2022
    Laravel package to search through multiple Eloquent models.

    Laravel package to search through multiple Eloquent models. Supports sorting, pagination, scoped queries, eager load relationships and searching through single or multiple columns.

    Protone Media 845 Jan 1, 2023
    A customisable Laravel Nova card that fetches data through ajax calls.

    Ajax Table Card Description A customisable Laravel Nova card that fetches data through ajax calls. Why? To allow displaying certain data on the dashbo

    TwentyOne34 Technologies Corp. 4 Mar 8, 2022