Scrappy Cocco
Scrappy Cocco

Reputation: 1204

How to use artisan to make views in laravel 5.1

I have been looking in the docs for a solution to make views with basic CURD operations but without much success.

I guess this might be pretty simple, but am missing something or not looking hard enough.

i can make models and controllers using the below artisan commands

php artisan make:model modelName

php artisan make:controller controllerName

But how do we make the basic CURD views. something like

 php artisan make:views

cant find any doc for this. Please help

Upvotes: 26

Views: 90646

Answers (7)

Eng_Farghly
Eng_Farghly

Reputation: 2997

You can install sven/artisan-view package to make view from CMD, to install package write this command:

composer require sven/artisan-view --dev

After installing it, you can make a single view or folder with all views that contain {index-create-update-show}

To make a single file we using this command:

php artisan make:view  Name_of_view

For example

php artisan make:view index

To make a folder that contain all resources index - create - update - show write name of folder that contain all this files for example:

php artisan make:view Name_of_Folder -r

For example:

php artisan make:view blog -r

-r is a shorthand for --resource you can write full name or shorthand to make resource.

you can extend yields from master page if master page inside in directory layouts we write command sith this format

php artisan make:view index --extends=layouts.master --with-yields

layouts is a directory this directory may be with a different name in your project the idea is name_of_folder/master_page that you want to extend yields from it.

For more view docs

Upvotes: 0

PHP Laravel Developer
PHP Laravel Developer

Reputation: 149

To create a view (blade) file through command in laravel 8:

composer require theanik/laravel-more-command --dev

php artisan make:view abc.blade.php

Upvotes: 3

Anik Anwar
Anik Anwar

Reputation: 805

There is very easy way to create a view(blade) file with php artisan make:view {view-name} command using Laravel More Command Package.

First Install Laravel More Command

composer require theanik/laravel-more-command --dev

Then Run

php artisan make:view {view-name}

For example

It create index.blade.php in resource/views directory

php artisan make:view index

It create index.blade.php in resource/views/user directory

php artisan make:view user/index

Thank you.

Upvotes: 5

umefarooq
umefarooq

Reputation: 4574

if you are using laravel 5.1 or 5.2 this gist can help you make:view command just create command copy and paste the code from gist.

Step 1:

php artisan make:command MakeViewCommand

Step 2:

copy class from this gist

https://gist.github.com/umefarooq/ebc617dbf88260db1448

Upvotes: 12

Priyash
Priyash

Reputation: 181

Laravel officially doesn't have any Artisan cammands for views.

But you could add third party plugins like Artisan View Here's the link Artisan View

After adding this plugin to your project by the guide provided here you should be able to perform following cammands :

  • 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
    

Upvotes: 6

user6735654
user6735654

Reputation: 33

In v5.4 you need to create the command with: php artisan make:command MakeView

and before you can use it, it must be registered in App/Console/Kernel like

protected $commands = [
        Commands\MakeView::class
    ];

then you make a view like: php artisan make:view posts/create

Upvotes: 3

Sven
Sven

Reputation: 454

At the time of writing, there isn't a way to create views via artisan without writing your own command or using a third party package. You could write your own as already suggested or use sven/artisan-view.

Upvotes: 19

Related Questions