arwp/mvc

For building Model-View-Controller (MVC) pattern in laravel

v1.1.20 2024-01-07 19:59 UTC

README

MVC Generator V1.0.1

MVC Generator is a powerful package designed to streamline the creation of new modules with CRUD functionality and generate corresponding views. This tool is a time-saving asset for your projects.
This library is specifically crafted for arwp/main-master, and its code structure is optimized to align seamlessly with that template.

Made with ❤️ by ARWP

Requirements

  • Laravel 10.0 or higher
  • PHP 8.1 or higher

Features

  • Utilize php artisan make:mvc [model name] to create a new module.
    • Controller (with CRUD functionality)
    • Model (with fillable fields and relationships)
    • Migration (with table creation and relationships)
    • Views (with CRUD functionality)
    • New route (with CRUD functionality)
  • Use php artisan delete:mvc [name] to delete a module (delete mvc files one by one with confirmation).
  • Use php artisan delete:mvc [name] --all to delete a module (delete all files and tables in the database).

How to install

$ composer require arwp/mvc

Create a new module

# run this command to create a new module
$ php artisan make:mvc [name of model]
# example 
$ php artisan make:mvc User 
# or custom command :
# e.g: php artisan make:mvc User mv to create model and view
$ php artisan make:mvc User mv #{m=model, v=view, c=controller, t=table/migration, r=route}
# or custom command :
$ php artisan make:mvc User view #['migration', 'model', 'view', 'controller', 'route']

Delete a module (delete all file and table in database)

# run this command to delete a module
$ php artisan delete:mvc [name of model]

Setup and Configuration :

add this code to your config/app.php

'providers' => [
    ...
    Arwp\Mvc\MvcServiceProvider::class,
    ...
]

you need to publish the resource file to your project

$ php artisan vendor:publish --provider="Arwp\Mvc\MvcServiceProvider"
  #publised file config/mvc.php
  #publised file routes/mvc-route.php
  #publised file Console/Commands/createMvc.php
  #publised file Console/Commands/deleteMvc.php

add this code to your routeServiceProvider.php

public function boot()
{
    ...
    Route::middleware(['web','auth','backend'])->namespace('App\Http\Controllers\Backend')->group(base_path('routes/mvc-route.php'));
    ...
}

open file config/mvc.php and change the key value to your path folder

return [
    'path_controller' => 'app/Http/Controllers/Backend', // this is path to controller folder
    'path_model' => 'app/Models', // this is path to model folder
    'path_view' => 'views/backend', // this is path to view folder (e.g: views/backend or views/frontend)
    'path_route' => 'routes/mvc-route.php', // path to route file (default: routes/mvc-route.php)
    'route_prefix' => '', // Customize with your "Prefix Route" (e.g: backend, admin, etc) (optional)
];

If you wish to modify the default "PATH ROUTE," you can make adjustments in the config/mvc.php file.

return [
    ...
    'path_route' => 'routes/web.php', // Change this to your desired route file path
    ...
];

Copy and paste the following code into your specified route file (e.g., routes/web.php):

//{{route replacer}} DON'T REMOVE THIS LINE

License

MVC Generator is released as open-source software under the MIT license.

This project is designed to enhance the efficiency and simplicity of your development process. I trust that this tool will prove valuable in accelerating your project development.

If you find this project beneficial, your support in the form of a star ⭐️ would be greatly appreciated. Thank you for your consideration and contribution.