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.
- laravel >= 7
Via composer:
composer require meshesha/artisan-make-mvc
php artisan vendor:publish --provider="Meshesha\ArtisanMakeMvc\ArtisanMakeMvcServiceProvider"
- 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',
];
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).
return [
"template" => "default", //templates: default (Vanilla CSS), bootstrap, tailwind
"extends" => "", //e.g: @extends('layouts.app')
"section" => "", //e.g: @section('content')
"endsection" => "", //e.g: @endsection
];
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');
php artisan mvc:undo
Will delete all recently created files.
-L | --list : shows history list
-S | --select : select from list for 'undo' action.
MIT License (MIT). Please see the license file for more information.