You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1 lines
11 KiB

[{"content":"About this package This package contains artisan make:crud commands to create a simple CRUD feature with test classes on our Laravel 5.5 (and later) application. This package is fairly simple, to boost test-driven development method on our laravel application.\nWith this package installed on local environment, we can use (e.g.) php artisan make:crud Vehicle command to generate some files :\n App\\Models\\Vehicle.php eloquent model xxx_create_vehicles_table.php migration file VehicleController.php index.blade.php and forms.blade.php view file in resources/views/vehicles directory resources/lang/vehicle.php lang file VehicleFactory.php model factory file VehiclePolicy.php model policy file in app/Policies directory ManageVehiclesTest.php feature test class in tests/Feature directory VehicleTest.php unit test class in tests/Unit/Models directory VehiclePolicyTest.php unit test class in tests/Unit/Policies directory It will update some file :\n Update routes/web.php to add vehicles resource route Update app/providers/AuthServiceProvider.php to add Vehicle model Policy class in $policies property It will also create this file if it not exists :\n resources/lang/app.php lang file if it not exists tests/BrowserKitTest.php base 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.\n","description":"This package contains artisan make:crud commands to create a simple CRUD feature with test classes on our Laravel application.","id":0,"section":"docs","tags":null,"title":"About this package","uri":"https://nafiesl.github.io/SimpleCrudGenerator/docs/about/"},{"content":"How to install For Laravel 8.x 1 2 # Get the package $ composer require luthfi/simple-crud-generator:^2.0 For Laravel 5.6 to 7.x 1 2 # Get the package $ composer require luthfi/simple-crud-generator:^1.0 For Laravel 5.5 To use this package on laravel 5.5, we need to add the package (with browserkit) within require-dev in composer.json file, like so :\n1 2 3 4 5 # Install required package for laravel/browser-kit-testing $ composer require symfony/css-selector:^3.0 # Get the package $ composer require luthfi/simple-crud-generator 1.2.* --dev ","description":"Install the package with composer.","id":1,"section":"docs","tags":null,"title":"How to install","uri":"https://nafiesl.github.io/SimpleCrudGenerator/docs/how-to-install/"},{"content":"How to use Just type in terminal $ php artisan make:crud ModelName command, it will create simple Laravel CRUD files of given model name completed with tests.\nFor example we want to create CRUD for \u0026lsquo;App\\Models\\Vehicle\u0026rsquo; model.\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 $ php artisan make:crud-simple Vehicle Vehicle resource route generated on routes/web.php. Vehicle model generated. Vehicle table migration generated. VehicleController 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! Make sure we have set database credential on .env file, then :\n1 2 $ php artisan migrate $ php artisan serve Then visit our application url: http://localhost:8000/vehicles.\nUsage on Fresh Install Laravel 8.x In this example, we are using the laravel installer package to install new laravel project.\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 # This is example commands for Ubuntu users. $ laravel new project-directory $ cd project-directory $ composer require laravel/ui $ php artisan ui bootstrap --auth $ npm install \u0026amp;\u0026amp; npm run dev # Might need to run twice, minimum requirement: NodeJS v12.x $ vim .env # Edit your .env file to update database configuration # Install the package $ composer require luthfi/simple-crud-generator:^2.0 # I really suggest \u0026#34;git commit\u0026#34; your project right before you run the make:crud command $ php artisan make:crud Vehicle # Model name in singular $ php artisan migrate $ php artisan serve # Visit your route http://127.0.0.1:8000 # Register as a new user # Visit your route http://127.0.0.1:8000/vehicles # Run the unit tests $ vim phpunit.xml # Remove comments on the DB_CONNECTION and DB_DATABASE lines $ vendor/bin/phpunit ","description":"How ot use the package.","id":2,"section":"docs","tags":null,"title":"How to use","uri":"https://nafiesl.github.io/SimpleCrudGenerator/docs/how-to-use/"},{"content":"Available Commands Bootstrap 4 Views Full CRUD feature with tests 1 $ php artisan make:crud ModelName Simple CRUD feature with tests 1 $ php artisan make:crud-simple ModelName Bootstrap 3 views Full CRUD feature with tests 1 $ php artisan make:crud ModelName --bs3 Simple CRUD feature with tests 1 $ php artisan make:crud-simple ModelName --bs3 API CRUD feature with tests 1 $ php artisan make:crud-api ModelName ","description":"Available commands and options.","id":3,"section":"docs","tags":null,"title":"Available Commands","uri":"https://nafiesl.github.io/SimpleCrudGenerator/docs/available-commands/"},{"content":"Model Attribute/Column The Model and table will only have 2 pre-definded attributes or columns : title and description on each generated model and database table. You can continue working on other column on the table.\n","description":"Model attributes or column generated by the package.","id":4,"section":"docs","tags":null,"title":"Model Attribute/Column","uri":"https://nafiesl.github.io/SimpleCrudGenerator/docs/model-attributes/"},{"content":"Views Bootstrap 4 Views The generated view files use Bootstrap 4 by default (for Laravel 5.6 and later).\nBootstrap 3 Views We can also generates views that use Bootstrap 3 with --bs3 command option, eg for Laravel version 5.5.\nThe Default Layout View You need a resources/views/layouts/app.blade.php view file, simply create one with php artisan make:auth command. You can change this configuration via the config/simple-crud.php file.\n","description":"The generated views are using bootstrap frontend framework.","id":5,"section":"docs","tags":null,"title":"Views","uri":"https://nafiesl.github.io/SimpleCrudGenerator/docs/views/"},{"content":"For API If we want to generate API Controller with feature tests, we use following command :\n1 $ php artisan make:crud-api Vehicle By default, we use Laravel Token Based Authentication, so we need to update our user model.\n Add api_token column on our users_table_migration. Add api_token as fillable property on User model. Add api_token field on our UserFactory. API Usage The generated API is a REST API, using GET and POST verbs, with a URI of /api/modelname.\nExample code for calling the generated API, using Guzzle:\n// Read data a specific Vehicle record... $uri = 'http://your-domain.com/api/vehicles/'.$vehicleID; $headers = ['Authorization' =\u0026gt; 'Bearer '.$apiToken]; $client = new \\GuzzleHttp\\Client(); $res = $client-\u0026gt;request('GET', $uri, ['headers' =\u0026gt; $headers]); // Create a new Vehicle record... $uri = 'http://your-domain.com/api/vehicles'; $headers = ['Authorization' =\u0026gt; 'Bearer '.$apiToken]; $payload = json_encode([ 'title' =\u0026gt; 'Vehicle Name 1', 'description' =\u0026gt; 'Vehicle Description 1', ]); $client = new \\GuzzleHttp\\Client(); $res = $client-\u0026gt;request('POST', $uri, ['body' =\u0026gt; $payload, 'headers' =\u0026gt; $headers]); The generated functional tests will give you examples of how to adapt this code for other call types.\n","description":"Generates API endpoints for model CRUD.","id":6,"section":"docs","tags":null,"title":"For API","uri":"https://nafiesl.github.io/SimpleCrudGenerator/docs/for-api/"},{"content":"Config File You can configure your own by publishing the config file:\n1 $ php artisan vendor:publish --provider=\u0026#34;Luthfi\\CrudGenerator\\ServiceProvider\u0026#34; --tag=config That will generate config/simple-crud.php file.\nBy default, this package have some configuration:\n1 2 3 4 5 6 7 8 9 10 11 12 \u0026lt;?php return [ // The master view layout that generated views will extends \u0026#39;default_layout_view\u0026#39; =\u0026gt; \u0026#39;layouts.app\u0026#39;, // The base test case class path for generated testing classes \u0026#39;base_test_path\u0026#39; =\u0026gt; \u0026#39;tests/BrowserKitTest.php\u0026#39;, // The base test class full name \u0026#39;base_test_class\u0026#39; =\u0026gt; \u0026#39;Tests\\BrowserKitTest\u0026#39;, ]; ","description":"Configure the package with config file.","id":7,"section":"docs","tags":null,"title":"Config File","uri":"https://nafiesl.github.io/SimpleCrudGenerator/docs/config-file/"},{"content":"Publishing the stub files Stub files is the templates which we use to generate the code for each model classes and files. We can customize the stub files as we needed by publishing them to our project directory.\n1 $ php artisan vendor:publish --provider=\u0026#34;Luthfi\\CrudGenerator\\ServiceProvider\u0026#34; --tag=stubs That will generate stub files on stubs/simple-crud directory. Now we can change some stub files based on our project needs.\n","description":"Use your own stub files.","id":8,"section":"docs","tags":null,"title":"Publishing the stub files","uri":"https://nafiesl.github.io/SimpleCrudGenerator/docs/publishing-the-stub-files/"},{"content":"Screenshots Visit your application in new resource route : http://127.0.0.1:8000/vehicles\n","description":"Some screenshots of the generated CRUD feature.","id":9,"section":"docs","tags":null,"title":"Screenshots","uri":"https://nafiesl.github.io/SimpleCrudGenerator/docs/screenshots/"},{"content":"Generated Testing Suite Next, let us try the generated testing suite. 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 :\n1 2 3 4 5 6 7 8 \u0026lt;phpunit\u0026gt; \u0026lt;!-- ..... --\u0026gt; \u0026lt;php\u0026gt; \u0026lt;!-- ..... --\u0026gt; \u0026lt;server name=\u0026#34;DB_CONNECTION\u0026#34; value=\u0026#34;sqlite\u0026#34;/\u0026gt; \u0026lt;server name=\u0026#34;DB_DATABASE\u0026#34; value=\u0026#34;:memory:\u0026#34;/\u0026gt; \u0026lt;/php\u0026gt; \u0026lt;/phpunit\u0026gt; Then run PHPUnit\n1 $ vendor/bin/phpunit All tests should be passed.\n","description":"Some screenshots of the generated CRUD feature.","id":10,"section":"docs","tags":null,"title":"Generated Testing Suite","uri":"https://nafiesl.github.io/SimpleCrudGenerator/docs/generated-testing-suite/"},{"content":"License This package is open-sourced software licensed under the MIT license.\n","description":"Some screenshots of the generated CRUD feature.","id":11,"section":"docs","tags":null,"title":"License","uri":"https://nafiesl.github.io/SimpleCrudGenerator/docs/license/"}]