milwad/laravel-crod

Make easy & fast crud

Fund package maintenance!
milwad

v1.4.1 2024-03-28 18:33 UTC

This package is auto-updated.

Last update: 2024-04-15 14:33:17 UTC


README

68747470733a2f2f62616e6e6572732e6265796f6e64636f2e64652f4c61726176656c25323043726f642e706e673f7468656d653d6c69676874267061636b6167654d616e616765723d636f6d706f7365722b72657175697265267061636b6167654e616d653d6d696c7761642532466c61726176656c2d63726f64267061747465726e3d617263686974656374267374796c653d7374796c655f31266465736372697074696f6e3d47656e65726174652b637275642b66696c65732b65617379266d643d312673686f7757617465726d61726b3d3026666f6e7453697a653d313030707826696d616765733d68747470732533412532462532466c61726176656c2e636f6d253246696d672532466c6f676f6d61726b2e6d696e2e737667

Latest Stable Version Total Downloads License Passed Tests PHP Version Require

Laravel crod is a package for implementing CRUD faster and easier.
You can create controllers, models, migrations, services, repositories, views and requests quickly.
You can make automatically fillable for models, query for repositories and services, make resource functions for controllers, and a lot of options.

Docs: https://github.com/milwad-dev/laravel-crod/wiki

Requirements

  • PHP: ^8.0
  • Laravel framework: ^9
  • doctrine/dbal: ^3.6
Crod L7 L8 L9 L10
1.0
1.1
1.2
1.3

Installation

composer require milwad/laravel-crod

After publish config files.

php artisan vendor:publish --provider="Milwad\LaravelCrod\LaravelCrodServiceProvider" --tag="laravel-crod-config"

Check active commands

Run the command in cmd or terminal.

php artisan

You must see this command in the terminal. Crod commands

Make CRUD files

This command creates CRUD files, Run this command in the terminal.

php artisan crud:make {name}

For example

php artisan crud:make Product

When you execute this command, after creating the files, you will see a list of options that will create a series of additional files for you, which of course are optional, you can choose and if you need, it will create additional files for you such as seeder, factory, repository, etc.

✅ After you can see crod creates files for crud

CRUD query

This command adds query and date to CRUD files.

** You must run the migrate command. **

php artisan migrate

Run this command in the terminal.

php artisan crud:query {table_name} {model} {--id-controller}

For example

php artisan crud:query products Product

When write --id-controller option add function without route model binding.

After you can see add query to service, repository, controller, model, etc.

CRUD for module

Run this command in the terminal, This command created CRUD file for module.

php artisan crud:make-module {module_name}

For example

php artisan crud:make-module Product

When you execute this command, after creating the files, you will see a list of options that will create a series of additional files for you, which of course are optional, you can choose and if you need, it will create additional files for you such as seeder, factory, repository, etc.

CRUD query from module

This command adds query and date to CRUD files for module.

** You must run your migration file. **

php artisan crud:query-module {table_name} {model} {--id-controller}

For example

php artisan crud:query-module products Product

OR

php artisan crud:query-module products Product --id-controller

When write --id-controller option add function without route model binding.

After you can see add query to service, repository, controller, model, etc for module.

Custom path

You can custom file path in config file. config/laravel-crod.php

<?php

return [
    /*
     * Repository namespace.
     *
     * This is a word that move into the latest name of repository file, for ex: ProductRepo.
     * If this value is changed, any repos that are created will be renamed, for ex: ProductRepository.
    */
    'repository_namespace' => 'Repo',

    /*
     * Get main controller.
     *
     * This is a namespace of main controller that default path is `App\Http\Controllers\Controller`.
     */
    'main_controller' => 'App\Http\Controllers\Controller',

    /*
     * Are using PEST?
     *
     * If you are using PEST framework, you can change it this value to `true`.
     */
    'are_using_pest' => false,

    /*
     * Route namespace.
     *
     * This is a word that move into the latest name of route file.
     */
    'route_namespace' => '',

    /*
     * Route name.
     *
     * This is a word that name of route file.
     */
    'route_name' => 'web',

    /*
     * Modules config.
     *
     * You can make custom modules with special folders ... .
     */
    'modules' => [
        'module_namespace'  => 'Modules', // This value is for the name of the folder that the modules are in.
        'model_path'        => 'Entities', // This value is for the name of the folder that contains the module models.
        'migration_path'    => 'Database\Migrations', // This value is for the name of the folder that contains the module migrations.
        'controller_path'   => 'Http\Controllers', // This value is for the name of the folder that contains the module controllers.
        'request_path'      => 'Http\Requests', // This value is for the name of the folder that contains the module requests-form.
        'view_path'         => 'Resources\Views', // This value is for the name of the folder that contains the module views.
        'service_path'      => 'Services', // This value is for the name of the folder that contains the module services.
        'repository_path'   => 'Repositories', // This value is for the name of the folder that contains the module Repositories.
        'feature_test_path' => 'Tests\Feature', // This value is for the name of the folder that contains the module feature-tests.
        'unit_test_path'    => 'Tests\Unit', // This value is for the name of the folder that contains the module unit-tests.
        'provider_path'     => 'Providers', // This value is for the name of the folder that contains the module providers.
        'factory_path'      => 'Database\Factories', // This value is for the name of the folder that contains the module factories.
        'seeder_path'       => 'Database\Seeders', // This value is for the name of the folder that contains the module seeders.
        'route_path'        => 'Routes', // This value is for the name of the folder that contains the module routes.
    ],

    /*
     * Queries.
     *
     * This is some config for add queries.
     */
    'queries' => [
        /*
         * Except columns in fillable.
         *
         * This `except_columns_in_fillable` must be arrayed!
         * This `except_columns_in_fillable` that remove field from $fillable in model.
         */
        'except_columns_in_fillable' => [
            'id', 'updated_at', 'created_at',
        ],
    ],
];

This config file is very helpful to custom path or latest name file.

License

  • This package is created and modified by Milwad Khosravi for Laravel >= 9 and is released under the MIT License.

Testing

Run the tests with:

vendor/bin/phpunit
composer test
composer test-coverage

Contributing

This project exists thanks to all the people who contribute. CONTRIBUTING

68747470733a2f2f6f70656e636f6c6c6563746976652e636f6d2f6c61726176656c2d63726f642f636f6e7472696275746f72732e7376673f77696474683d38393026627574746f6e3d66616c7365

Security

If you've found a bug regarding security please mail milwad.dev@gmail.com instead of using the issue tracker.

Conclusion

Laravel-crod is a simple yet powerful package that can help you create CRUD operations for your Laravel models in just a few lines of code. By following this documentation, you should now have a better understanding of how to use the package in your Laravel project. If you have any issues or questions, please feel free to open an issue on the package's GitHub repository.