|
|
8 years ago | |
|---|---|---|
| screenshots | 8 years ago | |
| src | 8 years ago | |
| tests | 8 years ago | |
| .gitattributes | 8 years ago | |
| .gitignore | 8 years ago | |
| .travis.yml | 8 years ago | |
| LICENSE | 8 years ago | |
| composer.json | 8 years ago | |
| phpunit.xml | 8 years ago | |
| readme.md | 8 years ago | |
readme.md
Laravel Simple CRUD Generator
An artisan make:crud command to create a simple CRUD feature on your Laravel 5.5 application.
About this package
With this package installed on local environment, we can use (e.g.) php artisan make:crud Vehicle command to generate some files :
App\Vehicle.phpeloquent modelxxx_create_vehicles_table.phpmigration fileVehiclesController.phpindex.blade.phpandforms.blade.phpview file inresources/views/vehiclesdirectoryresources/lang/vehicle.phplang fileVehicleFactory.phpmodel factory fileVehiclePolicy.phpmodel policy file inapp/PoliciesdirectoryManageVehiclesTest.phpfeature test class intests/FeaturedirectoryVehicleTest.phpunit test class intests/Unit/ModelsdirectoryVehiclePolicyTest.phpunit test class intests/Unit/Policiesdirectory
It will update some file :
- Update
routes/web.phpto addvehiclesresource route - Update
app/providers/AuthServiceProvider.phpto add Vehicle model Policy class in$policiesproperty
It will also create this file if it not exists :
resources/lang/app.phplang file if it not existstests/BrowserKitTest.phpbase Feature TestCase class if it not exists
Main purpose
The main purpose of this package is for faster Test-driven Development, it generates model CRUD scaffolds complete with Testing Classes which will use Laravel Browserkit Testing package and PHPUnit version 6.
Model Attribute/column
The Model and table will only have 2 pre-definded attributes or columns : name and description on each generated model and database table. You can continue working on other column on the table.
How to install
# Bootstrap Form Field generator
$ composer require luthfi/formfield
# Get the package
$ composer require luthfi/simple-crud-generator --dev
How to use
The package will auto-discovered in Laravel 5.5. Just type in terminal:
$ php artisan
We will find the make:crud command, it will Create simple Laravel CRUD files of given model name.
$ php artisan make:crud Vehicle
Vehicle resource route generated on routes/web.php.
Vehicle model generated.
Vehicle table migration generated.
VehiclesController generated.
Vehicle index view file generated.
Vehicle form view file generated.
lang/app.php generated.
vehicle lang files generated.
Vehicle model factory generated.
Vehicle model policy generated.
AuthServiceProvider class has been updated.
BrowserKitTest generated.
ManageVehiclesTest generated.
VehicleTest (model) generated.
VehiclePolicyTest (model policy) generated.
CRUD files generated successfully!
Create mysql database, set your database credential on .env file. Then :
$ php artisan migrate
$ php artisan serve
Config file
By default, this package have some configuration:
<?php
return [
// The master view layout that generated views will extends
'default_layout_view' => 'layouts.app',
// The base test case class path for generated testing classes
'base_test_path' => 'tests/BrowserKitTest.php',
// The base test class full name
'base_test_class' => 'Tests\BrowserKitTest',
];
You can configure your own by publishing the config file:
$ php artisan vendor:publish --provider="Luthfi\CrudGenerator\ServiceProvider"
That will generate config/simple-crud.php file.
Attention
- The package will creates the Model class file, the command will stop if the Model already exists.
- You need a
resources/views/layouts/app.blade.phpview file, simply create one withphp artisan make:authcommand. You can change this configuration via theconfig/simple-crud.phpfile.
Screenshots
Visit your application in new resource route : http://127.0.0.1:8000/vehicles
Let's try the generated testing suite
Next, to use the generated testing classes, we can set the database environment using in-memory database SQLite. Open phpunit.xml. Add two lines below on the env :
<phpunit>
<!-- ..... -->
<php>
<!-- ..... -->
<env name="DB_CONNECTION" value="sqlite"/>
<env name="DB_DATABASE" value=":memory:"/>
</php>
</phpunit>
Then run PHPUnit
$ vendor/bin/phpunit
All tests should be passed.
License
This package is open-sourced software licensed under the MIT license.

