lanciweb/laravel-make-view
Laravel package adding an artisan make:view command to generate Blade view files. Create single views using dot notation (auto-creates nested folders) or scaffold conventional CRUD resource views (index, show, create, edit) with --crud/-c.
Installation:
composer require lanciweb/laravel-make-view
Publish the config (if needed) with:
php artisan vendor:publish --provider="Lanciweb\MakeView\MakeViewServiceProvider"
First Use Case: Generate a single view for a home page:
php artisan make:view home
This creates resources/views/home.blade.php.
Where to Look First:
config/makeview.php for customization options (e.g., default view path, stubs).stubs/ directory in the package (if published) to understand template structure.Nested View Generation: Use dot notation to create nested directories:
php artisan make:view admin.dashboard.analytics
Creates resources/views/admin/dashboard/analytics.blade.php.
CRUD Workflow:
For resource controllers, use the --crud flag to generate all standard views:
php artisan make:view posts --crud
Outputs:
resources/views/posts/
├── index.blade.php
├── show.blade.php
├── create.blade.php
└── edit.blade.php
Custom Stubs:
resources/stubs/:
php artisan vendor:publish --tag=makeview-stubs
resources/stubs/views/blank.blade.stub) to modify generated templates.Integration with Controller Generation:
Combine with make:controller for a full CRUD setup:
php artisan make:controller PostController --resource
php artisan make:view posts --crud
Dynamic View Paths:
Use the --path option to specify a custom directory:
php artisan make:view admin.posts --crud --path=resources/views/custom
Rapid Prototyping: Generate views alongside controllers to scaffold features quickly. Example:
php artisan make:controller UserController --resource
php artisan make:view users --crud
Component-Based Views:
Generate partials (e.g., _header.blade.php) by omitting the --crud flag and using underscores in the name:
php artisan make:view _partials.header
Team Onboarding:
Standardize view structure by configuring default stubs (e.g., add @extends('layouts.app') to all views).
Stub Overrides:
{{ $slot }}).resources/stubs/views/.Directory Permissions:
resources/views/ lacks write permissions.chmod -R 755 resources/views/ or use --path to a writable directory.CRUD Naming Conflicts:
--crud for a route that already has views (e.g., posts) will overwrite existing files.--force cautiously.Dot Notation Edge Cases:
admin..posts) or invalid characters (e.g., admin/posts) may cause errors.Config Overrides:
view_path in config/makeview.php defaults to resources/views/. Changing this affects all future generations.Verbose Output:
Use --verbose to see the exact path being generated:
php artisan make:view admin.posts --crud -v
Stub Debugging:
Add {{ dd('Stub loaded') }} to stubs to verify they’re being used.
Command Customization:
Extend the command by publishing the service provider and overriding methods in app/Providers/MakeViewServiceProvider.php.
Aliases:
Add a custom alias to your .bashrc or aliases file:
alias mv='php artisan make:view'
Usage:
mv admin.dashboard --crud
Partial Generation:
Use @include directives in stubs to auto-generate common partials (e.g., _form.blade.php).
Testing: Mock the command in PHPUnit tests:
$this->artisan('make:view test.view')
->expectsOutput('resources/views/test/view.blade.php')
->assertExitCode(0);
IDE Integration:
Configure your IDE (e.g., PHPStorm) to recognize generated Blade files by adding resources/views/**/*.blade.php to "Files to Watch."
Custom Templates:
Create a resources/stubs/views/custom.blade.stub and reference it via --stub=custom:
php artisan make:view home --stub=custom
Environment-Specific Views:
Use the --path option to generate environment-specific views (e.g., resources/views/staging/).
How can I help you explore Laravel packages today?