jundayw / laravel-artisan-generator
laravel artisan generator
v5.0.0
2023-03-10 12:38 UTC
Requires
- php: >=7.2.0
This package is auto-updated.
Last update: 2024-11-10 16:17:24 UTC
README
命令行下, 执行 composer 命令安装:
composer require jundayw/laravel-artisan-generator
配置及模板
authentication package that is simple and enjoyable to use.
发布配置文件
php artisan vendor:publish --tag=artisan-generator-config
发布模板文件
php artisan vendor:publish --tag=artisan-generator-views
发布配置及模板文件
php artisan vendor:publish --provider="Jundayw\LaravelArtisanGenerator\GeneratorServiceProvider"
使用方法
分步交互命令:generator
可生成Controller/Repository/Model/Request/View及相对应的方法(Method)
php artisan generator
生成模型命令:generator:model
php artisan generator:model UpgradeStation php artisan generator:model UpgradeStation --parent
[ "DummyModelRootNamespace" => "App\Models" "DummyModelClassNamespace" => "App\Models\UpgradeStation" "DummyModelClass" => "UpgradeStation" "DummyModelVariable" => "upgradeStation" "DummyModelKebabVariable" => "upgrade-station" "DummyModelSnakeVariable" => "upgrade_station" "DummyNamespace" => "App\Models" "DummyRootNamespace" => "App\\" "NamespacedDummyUserModel" => "App\Models\User" ]
生成表单验证命令:generator:request
php artisan generator:request Backend/UpgradeStationCreateRequest php artisan generator:request Backend/UpgradeStationCreateRequest --parent
[ "DummyRepositoryRootNamespace" => "App\Http\Requests" "DummyRequestClassNamespace" => "App\Http\Requests\Backend\UpgradeStationCreateRequest" "DummyRequestClass" => "UpgradeStationCreateRequest" "DummyRequestVariable" => "upgradeStationCreateRequest" "DummyRequestKebabVariable" => "upgrade-station-create-request" "DummyRequestSnakeVariable" => "upgrade_station_create_request" "DummyNamespace" => "App\Http\Requests\Backend" "DummyRootNamespace" => "App\\" "NamespacedDummyUserModel" => "App\Models\User" ]
生成仓储层命令:generator:repository
php artisan generator:repository Backend/UpgradeStationRepository php artisan generator:repository Backend/UpgradeStationRepository --parent php artisan generator:repository Backend/UpgradeStationRepository --model=UpgradeStation php artisan generator:repository Backend/UpgradeStationRepository --model=UpgradeStation --method
[ "DummyModelRootNamespace" => "App\Models" "DummyModelClassNamespace" => "App\Models\UpgradeStation" "DummyModelClass" => "UpgradeStation" "DummyModelVariable" => "upgradeStation" "DummyModelKebabVariable" => "upgrade-station" "DummyModelSnakeVariable" => "upgrade_station" "DummyRepositoryRootNamespace" => "App\Repositories" "DummyRepositoryClassNamespace" => "App\Repositories\Backend\UpgradeStationRepository" "DummyRepositoryClass" => "UpgradeStationRepository" "DummyRepositoryVariable" => "upgradeStationRepository" "DummyRepositoryKebabVariable" => "upgrade-station-repository" "DummyRepositorySnakeVariable" => "upgrade_station_repository" "DummyRepositoryUrl" => "backend/upgrade-station" "DummyRepositoryRoute" => "backend.upgrade-station" "DummyNamespace" => "App\Repositories\Backend" "DummyRootNamespace" => "App\\" "NamespacedDummyUserModel" => "App\Models\User" ]
生成视图命令:generator:view
php artisan generator:view Backend/UpgradeStation --view=list
[ "DummyViewRootNamespace" => "resources\views" "DummyViewClassNamespace" => "resources\views\Backend\UpgradeStation" "DummyViewClass" => "UpgradeStation" "DummyViewVariable" => "upgradeStation" "DummyViewKebabVariable" => "upgrade-station" "DummyViewSnakeVariable" => "upgrade_station" "DummyViewUrlMethod" => "backend/upgrade-station/list" "DummyViewRouteMethod" => "backend.upgrade-station.list" "DummyViewUrlClass" => "backend/upgrade-station" "DummyViewRouteClass" => "backend.upgrade-station" "DummyViewMethod" => "list" "DummyViewNamespaceRoot" => "backend" "DummyNamespace" => "resources\views\Backend" "DummyRootNamespace" => "resources\\" "NamespacedDummyUserModel" => "App\Models\User" ]
生成控制层命令:generator:controller
php artisan generator:controller Backend/UpgradeStationController php artisan generator:controller Backend/UpgradeStationController --parent php artisan generator:controller Backend/UpgradeStationController --model=UpgradeStation php artisan generator:controller Backend/UpgradeStationController --repository=Backend/UpgradeStationRepository php artisan generator:controller Backend/UpgradeStationController --repository=Backend/UpgradeStationRepository --model=UpgradeStation php artisan generator:controller Backend/UpgradeStationController --repository=Backend/UpgradeStationRepository --model=UpgradeStation --method --view=create --view=edit --view=list php artisan generator:controller Backend/UpgradeStationController --repository=Backend/UpgradeStationRepository --model=UpgradeStation --method --request=Backend/UpgradeStationCreateRequest --request=Backend/UpgradeStationUpdateRequest
[ "DummyRepositoryRootNamespace" => "App\Repositories" "DummyRepositoryClassNamespace" => "App\Repositories\Backend\UpgradeStationRepository" "DummyRepositoryClass" => "UpgradeStationRepository" "DummyRepositoryVariable" => "upgradeStationRepository" "DummyRepositoryKebabVariable" => "upgrade-station-repository" "DummyRepositorySnakeVariable" => "upgrade_station_repository" "DummyModelRootNamespace" => "App\Models" "DummyModelClassNamespace" => "App\Models\UpgradeStation" "DummyModelClass" => "UpgradeStation" "DummyModelVariable" => "upgradeStation" "DummyModelKebabVariable" => "upgrade-station" "DummyModelSnakeVariable" => "upgrade_station" "DummyRequestRootNamespace" => "App\Http\Requests" "DummyRequestClass1Namespace" => "App\Http\Requests\Backend\UpgradeStationCreateRequest" "DummyRequestClass1" => "UpgradeStationCreateRequest" "DummyRequestVariable1" => "upgradeStationCreateRequest" "DummyRequestKebabVariable1" => "upgrade-station-create-request" "DummyRequestSnakeVariable1" => "upgrade_station_create_request" "DummyRequestClass2Namespace" => "App\Http\Requests\Backend\UpgradeStationUpdateRequest" "DummyRequestClass2" => "UpgradeStationUpdateRequest" "DummyRequestVariable2" => "upgradeStationUpdateRequest" "DummyRequestKebabVariable2" => "upgrade-station-update-request" "DummyRequestSnakeVariable2" => "upgrade_station_update_request" "DummyViewVariableCreate" => "backend.upgrade-station.create" "DummyViewVariableEdit" => "backend.upgrade-station.edit" "DummyViewVariableList" => "backend.upgrade-station.list" "DummyLabel" => "Manager" "DummyControllerRootNamespace" => "App\Http\Controllers" "DummyControllerClassNamespace" => "App\Http\Controllers\Backend\UpgradeStationController" "DummyControllerClass" => "UpgradeStationController" "DummyControllerVariable" => "upgradeStationController" "DummyControllerKebabVariable" => "upgrade-station-controller" "DummyControllerSnakeVariable" => "upgrade_station_controller" "DummyNamespace" => "App\Http\Controllers\Backend" "DummyRootNamespace" => "App\\" "NamespacedDummyUserModel" => "App\Models\User" ]
使用流程
- 创建测试数据库
CREATE TABLE `upgrade_station` ( `id` int(11) NOT NULL AUTO_INCREMENT, `title` varchar(255) DEFAULT NULL, `created_at` datetime DEFAULT NULL, `updated_at` datetime DEFAULT NULL, `deleted_at` datetime DEFAULT NULL, `state` varchar(255) DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
- 编写测试路由
Route::namespace('Backend')->name('backend.')->group(function () { Route::prefix('upgrade-station')->name('upgrade-station.')->group(function () { Route::get('list', 'UpgradeStationController@list')->name('list'); Route::get('create', 'UpgradeStationController@create')->name('create'); Route::post('store', 'UpgradeStationController@store')->name('store'); Route::get('edit', 'UpgradeStationController@edit')->name('edit'); Route::post('update', 'UpgradeStationController@update')->name('update'); Route::get('destroy', 'UpgradeStationController@destroy')->name('destroy'); }); });
- 执行命令
php artisan generator:controller Backend/UpgradeStationController --repository=Backend/UpgradeStationRepository --model=UpgradeStation --method --request=Backend/UpgradeStationCreateRequest --request=Backend/UpgradeStationUpdateRequest --view=create --view=edit --view=list
或
php artisan generator
- 调试成功
- 发布模板文件
php artisan vendor:publish --tag=artisan-generator-views
- 自定义Model模板(继承、配置及默认方法)
- 自定义Request模板(继承、配置及默认方法)
- 自定义Repository模板(继承及默认方法)
- 自定义Controller模板(继承及默认方法)
- 自定义View视图文件(View模板默认create/edit/list,可根据具体情况新增或删减,通过 --view 参数调用新增模板)
- Well Done!