meshesha / artisan-make-mvc
Laravel artisan command to create view, controller and route from existing Model
Requires
- php: ^8.0
- doctrine/dbal: ^3.7
Requires (Dev)
- laravel/framework: ^8.0 || ^9.0
- phpunit/phpunit: ^9.0 || ^10.0
This package is auto-updated.
Last update: 2025-03-12 23:10:43 UTC
README
Laravel package that adds artisan command to create CRUD files and actions which includes: views (index,create,show,edit) , controller , add a route , factory and test . It depends on the existing model. And all this in a single command line.
Requirements
- laravel >= 7
Installation
Downloading
Via composer:
composer require meshesha/artisan-make-mvc
Publish config file
php artisan vendor:publish --provider="Meshesha\ArtisanMakeMvc\ArtisanMakeMvcServiceProvider"
Usage
- This package depends on an existing model. So it is required to create a model:
php artisan make:model Post -m
-
complete the required column names in the migration file, and migrate to the database.
-
Inside the model file you must add $fillable
protected $fillable = [ 'title', 'body', ];
Command options
php artisan make:mvc {model} {--W|incviews=true} {--F|viewfolder=} {--H|includehidden=true} {--C|inccontroller=true} {--R|incroute=true}
model : the existing model name (required) (e.g. 'Post')
--incviews | -W : Whether to include\create blade views (optional) (default value : true).
--viewfolder | -F : sub folder inside "resources\views" (optional) (default value : db table name of model (e.g. : 'posts'))
--includehidden | -H : Whether to include hidden fields that are mentioned in the model via 'protected $hidden' (optional) (default value : false)
--inccontroller | -C : Whether to include\create controller (optional) (default value : true)
--incroute | -R : Whether or not to add a route to the routers file (optional) (default value : true)
--factory : Add factory file (ModelNameFactory.php) in "database/Factories" directory.
--test : Add test file (ModelNameTest.php) in "tests/Feature" directory and factory file in "database/Factories" directory (because it is required for testing).
Config file (config\ArtisanMakeMvc.php)
return [ "template" => "default", //templates: default (Vanilla CSS), bootstrap, tailwind "extends" => "", //e.g: @extends('layouts.app') "section" => "", //e.g: @section('content') "endsection" => "", //e.g: @endsection ];
Example:
php artisan make:mvc Post
# 'Post' - model name
This command will create:
- PostController.php
- views/posts/create.blade.php
- views/posts/edit.blade.php
- views/posts/index.blade.php
- views/posts/show.blade.php
And add to routes/web.php: For laravel version >= 8.0.0
// posts: Route::resource('posts', App\Http\Controllers\PostController::class);
For laravel version < 8.0.0
// posts: Route::resource('posts', 'PostController');
undo
undo last action
php artisan mvc:undo
Will delete all recently created files.
more options:
-L | --list : shows history list
-S | --select : select from list for 'undo' action.
License
MIT License (MIT). Please see the license file for more information.