CRUD PORTO and Angular Generator Container for apiato 4.0.2

This is a PORTO Container for apiato 4.0.2 to scaffold you applications, at the moment the package generates the API stuff only, and generates an Angular 2+ module that consumes the generated container API. There is a lot of work to do, pull requests are very welcome!! ^_^

If you don't know apiato already, go to the apiato DOCS site and give it a try, it's an amazing project!!

NOTE: This container is tested on Laravel Homestead, so I sugest you to use Homestead as your development environment.


From the apiato root folder:

git clone app/Containers/Crud
# this will add some Codeception helpers and criterias on Ship folder
php artisan vendor:publish --provider="App\Containers\Crud\Providers\MainServiceProvider" --tag=classes
composer update

If you have foreign keys on your table, the generated transformer will try to hash that foreign keys with this method that you must put in App\Ship\Parents\Transformers\Transformer abstract class:

    public function hashKey($id)
        if (config('apiato.hash-id')) {
            return Hashids::encode($id);

        return $id;

If you will use the SelectListFrom{Entity} endpoint, add this method on App\Ship\Parents\Repositories\Repository:

     * Return model list to be used on selects. The $key and $value parameters
     * says what the array item keys names should be. Example with $key = 'id'
     * and $value = 'label':
     * [
     *     [ 'id' => 1, 'label' => 'Foo' ],
     *     [ 'id' => 2, 'label' => 'Bar' ],
     * ]
     * @param  string $key
     * @param  string $value
     * @return array
    public function selectList(string $key = 'id', string $value = 'text')
        return $this->model
            ->get(['id', 'name'])
            ->map(function ($item) use($key, $value) {
                return [
                    $key => $item->getHashedKey(),
                    $value => $item->name, // add more info for you convinience, if any


Let's suppose that we want to create a container called Library that will manage books data, so let's create that container folder and the migration file:

# from the apiato root folder
mkdir -p app/Containers/Library/Data/Migrations
php artisan make:migration create_books_table --create=books --path=app/Containers/Library/Data/Migrations

Next we add some columns to that migration table and run the migration:

php artisan migrate

Since this package use Codeception to generate the CRUD app test suit, you MUST bootstrap and generate the api suit for your container:

# from the apiato root folder
codecept bootstrap --namespace=Library app/Containers/Library/
codecept g:suit api -c app/Containers/Library/

Now you can go to to start configuring your CRUD container/module.

NOTE: the codeception stuff is required to run once per container, from here you can add more migration tables without setup codecept again.

After you have generated your container/module, you should run the generated tests to make shure that the generated code it's ok:

# from the apiato root folder
codecept build -c app/Containers/Library/ # required each time you generate CRUD for newly created table 
codecept run -c app/Containers/Library/
phpcbf app/Containers/Library/ --standard=PEAR,PSR1,PSR2 # optional, run any Code Beautifier you preffer
# from the Hello-Angular root folder
ng tests

What is Generated?

Here are a quick overview of the generated folders/files to give you the big idea of what is generated from a package named Library with an migration table called books, off course not a real life example, just have different kind of fields to prove some functionalities, this example is taking from the functional tests, check the up to date final generated code for this example in the CrudExample folder. So with the following setup:


The generated code will be:

apiato 4.0.2 Container

The generated container intends to follow the PORTO architectural pattern. A small difference with the apiato containers is that tests are generated with Codeception unless phpunit, these tests are namespaced with the container name. The generated API has some end points useful to work with the generated Angular module forms, e.g. serving a entity "Form Model/Select List" to build forms from server without update the Angular module, and have an entity list array to be used on select dropdowns (like some DB users list or something else). Obviosly the form builder on the Angular side is providen by the Hello-Angular project, the generated Angular module fits very well with Hello-Angular, but you can use it on your own main Angular project, just make sure to satisfy the dependencies from the generated module.

|─── Library
    β”œβ”€β”€ Actions
    β”‚Β Β  └── Book
    β”‚Β Β      β”œβ”€β”€ CreateBookAction.php
    β”‚Β Β      β”œβ”€β”€ DeleteBookAction.php
    β”‚Β Β      β”œβ”€β”€ GetBookAction.php
    β”‚Β Β      β”œβ”€β”€ ListAndSearchBooksAction.php
    β”‚Β Β      β”œβ”€β”€ RestoreBookAction.php
    β”‚Β Β      β”œβ”€β”€ SelectListFromBookAction.php
    β”‚Β Β      └── UpdateBookAction.php
    β”œβ”€β”€ composer.json
    β”œβ”€β”€ Configs
    β”‚Β Β  └── book-form-model.php
    β”œβ”€β”€ Data
    β”‚Β Β  β”œβ”€β”€ Criterias
    β”‚Β Β  β”‚Β Β  └── AdvancedBookSearchCriteria.php
    β”‚Β Β  β”œβ”€β”€ Factories
    β”‚Β Β  β”‚Β Β  └── BookFactory.php
    β”‚Β Β  β”œβ”€β”€ Migrations
    β”‚Β Β  β”œβ”€β”€ Repositories
    β”‚Β Β  β”‚Β Β  └── BookRepository.php
    β”‚Β Β  └── Seeders
    β”‚Β Β      └── BookPermissionsSeeder.php
    β”œβ”€β”€ Exceptions
    β”‚Β Β  β”œβ”€β”€ BookCreationFailedException.php
    β”‚Β Β  └── BookNotFoundException.php
    β”œβ”€β”€ Models
    β”‚Β Β  └── Book.php
    β”œβ”€β”€ Tasks
    β”‚Β Β  └── Book
    β”‚Β Β      β”œβ”€β”€ CreateBookTask.php
    β”‚Β Β      β”œβ”€β”€ DeleteBookTask.php
    β”‚Β Β      β”œβ”€β”€ GetBookTask.php
    β”‚Β Β      β”œβ”€β”€ ListAndSearchBooksTask.php
    β”‚Β Β      β”œβ”€β”€ RestoreBookTask.php
    β”‚Β Β      └── UpdateBookTask.php
    β”œβ”€β”€ tests
    β”‚Β Β  β”œβ”€β”€ acceptance
    β”‚Β Β  β”‚Β Β  └── _bootstrap.php
    β”‚Β Β  β”œβ”€β”€ acceptance.suite.yml
    β”‚Β Β  β”œβ”€β”€ api
    β”‚Β Β  β”‚Β Β  β”œβ”€β”€ Book
    β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ BookFormModelCest.php
    β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ CreateBookCest.php
    β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ DeleteBookCest.php
    β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ GetBookCest.php
    β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ ListAndSearchBooksCest.php
    β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ RestoreBookCest.php
    β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ SelectListFromBookCest.php
    β”‚Β Β  β”‚Β Β  β”‚Β Β  └── UpdateBookCest.php
    β”‚Β Β  β”‚Β Β  └── _bootstrap.php
    β”‚Β Β  β”œβ”€β”€ api.suite.yml
    β”‚Β Β  β”œβ”€β”€ _bootstrap.php
    β”‚Β Β  β”œβ”€β”€ _data
    β”‚Β Β  β”‚Β Β  └── dump.sql
    β”‚Β Β  β”œβ”€β”€ _envs
    β”‚Β Β  β”œβ”€β”€ functional
    β”‚Β Β  β”‚Β Β  └── _bootstrap.php
    β”‚Β Β  β”œβ”€β”€ functional.suite.yml
    β”‚Β Β  β”œβ”€β”€ _output
    β”‚Β Β  β”œβ”€β”€ _support
    β”‚Β Β  β”‚Β Β  β”œβ”€β”€ AcceptanceTester.php
    β”‚Β Β  β”‚Β Β  β”œβ”€β”€ ApiTester.php
    β”‚Β Β  β”‚Β Β  β”œβ”€β”€ FunctionalTester.php
    β”‚Β Β  β”‚Β Β  β”œβ”€β”€ _generated
    β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ AcceptanceTesterActions.php
    β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ FunctionalTesterActions.php
    β”‚Β Β  β”‚Β Β  β”‚Β Β  └── UnitTesterActions.php
    β”‚Β Β  β”‚Β Β  β”œβ”€β”€ Helper
    β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ Acceptance.php
    β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ Api.php
    β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ Functional.php
    β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ LibraryHelper.php
    β”‚Β Β  β”‚Β Β  β”‚Β Β  └── Unit.php
    β”‚Β Β  β”‚Β Β  └── UnitTester.php
    β”‚Β Β  β”œβ”€β”€ unit
    β”‚Β Β  β”‚Β Β  └── _bootstrap.php
    β”‚Β Β  └── unit.suite.yml
    └── UI
        └── API
            β”œβ”€β”€ Controllers
            β”‚Β Β  └── BookController.php
            β”œβ”€β”€ Requests
            β”‚Β Β  └── Book
            β”‚Β Β      β”œβ”€β”€ CreateBookRequest.php
            β”‚Β Β      β”œβ”€β”€ DeleteBookRequest.php
            β”‚Β Β      β”œβ”€β”€ FormModelFromBookRequest.php
            β”‚Β Β      β”œβ”€β”€ GetBookRequest.php
            β”‚Β Β      β”œβ”€β”€ ListAndSearchBooksRequest.php
            β”‚Β Β      β”œβ”€β”€ RestoreBookRequest.php
            β”‚Β Β      β”œβ”€β”€ SelectListFromBookRequest.php
            β”‚Β Β      └── UpdateBookRequest.php
            β”œβ”€β”€ Routes
            β”‚Β Β  β”œβ”€β”€ CreateBook.v1.private.php
            β”‚Β Β  β”œβ”€β”€ DeleteBook.v1.private.php
            β”‚Β Β  β”œβ”€β”€ FormModelFromBook.v1.private.php
            β”‚Β Β  β”œβ”€β”€ GetBook.v1.private.php
            β”‚Β Β  β”œβ”€β”€ ListAndSearchBooks.v1.private.php
            β”‚Β Β  β”œβ”€β”€ RestoreBook.v1.private.php
            β”‚Β Β  β”œβ”€β”€ SelectListFromBook.v1.private.php
            β”‚Β Β  └── UpdateBook.v1.private.php
            └── Transformers
                └── BookTransformer.php

If you don't want the main classes to be grouped on entity folders (e.g. Actions\Book\CreateBookAction), just leave unchecked the Group main apiato classes? on the GUI.

You should run the generated tests executing this command inside of the container to make sure that all is ok:

codecept run api

Angular Module

NOTE: To generate your Angular module you must have the respective generated apiato Container first. Why? Because the generator create fake data with the generated container factories on the Angular module tests.

This module is intended to work with this Hello-Angular application, when the generated module is placed in the Hello-Angular app (or your Angular app), then you must declare the module on the main modules array src/app/modules.ts file and reducers on the src/app/reducers.ts file, the reducers to be copied are commented on the generated entity.reducers.ts file to make things easy, following the Library/books exampΔΊe, said reducers should look something like this:

/* -----------------------------------------------------------------------------
Don't forget to import these reducer on the main app reducer!!

import * as fromBook from './library/reducers/book.reducer';

export interface State {
  book: fromBook.State;

const reducers = {
  book: fromBook.reducer,

// Book selectors
export const getBookState = (state: State) =>;
export const getBookSearchQuery = createSelector(getBookState, fromBook.getSearchQuery);
export const getBookFormModel = createSelector(getBookState, fromBook.getFormModel);
export const getBookFormData = createSelector(
  ) => ({
export const getBookList = createSelector(getBookState, fromBook.getItemsList);
export const getBooksPagination = createSelector(getBookState, fromBook.getItemsPagination);
export const getSelectedBook = createSelector(getBookState, fromBook.getSelectedItem);
export const getBookLoading = createSelector(getBookState, fromBook.getLoading);
export const getBookMessages = createSelector(getBookState, fromBook.getMessages);

----------------------------------------------------------------------------- */

The generated module intends to follow all the best practices on the Angular world based on the ngrx example app, Yatrum and many other resources. Some libraries used on the generated code are:

  • @ngrx/store
  • @ngrx/effects
  • @ngrx/router-store
  • ReactiveForms
  • @ngx-translate/core
  • ngx-bootstrap
  • etc...

The generated Angular module has many tests, you should execute these tests to ensure that everything is working as intendet by running ng test.

β”œβ”€β”€ library
    β”œβ”€β”€ actions
    β”‚Β Β  └── book.actions.ts
    β”œβ”€β”€ components
    β”‚Β Β  β”œβ”€β”€ book
    β”‚Β Β  β”‚Β Β  β”œβ”€β”€ book-abstract.component.ts
    β”‚Β Β  β”‚Β Β  β”œβ”€β”€ book-form.component.html
    β”‚Β Β  β”‚Β Β  β”œβ”€β”€ book-form.component.spec.ts
    β”‚Β Β  β”‚Β Β  β”œβ”€β”€ book-form.component.ts
    β”‚Β Β  β”‚Β Β  β”œβ”€β”€ book-search-advanced.component.html
    β”‚Β Β  β”‚Β Β  β”œβ”€β”€ book-search-advanced.component.spec.ts
    β”‚Β Β  β”‚Β Β  β”œβ”€β”€ book-search-advanced.component.ts
    β”‚Β Β  β”‚Β Β  β”œβ”€β”€ book-search-basic.component.html
    β”‚Β Β  β”‚Β Β  β”œβ”€β”€ book-search-basic.component.spec.ts
    β”‚Β Β  β”‚Β Β  β”œβ”€β”€ book-search-basic.component.ts
    β”‚Β Β  β”‚Β Β  β”œβ”€β”€ books-table.component.html
    β”‚Β Β  β”‚Β Β  β”œβ”€β”€ books-table.component.spec.ts
    β”‚Β Β  β”‚Β Β  β”œβ”€β”€ books-table.component.ts
    β”‚Β Β  β”‚Β Β  └── index.ts
    β”‚Β Β  └── index.ts
    β”œβ”€β”€ effects
    β”‚Β Β  β”œβ”€β”€ book.effects.ts
    β”‚Β Β  └── index.ts
    β”œβ”€β”€ library.module.ts
    β”œβ”€β”€ library-routing.module.ts
    β”œβ”€β”€ models
    β”‚Β Β  β”œβ”€β”€ bookPagination.ts
    β”‚Β Β  └── book.ts
    β”œβ”€β”€ pages
    β”‚Β Β  β”œβ”€β”€ book
    β”‚Β Β  β”‚Β Β  β”œβ”€β”€
    β”‚Β Β  β”‚Β Β  β”œβ”€β”€
    β”‚Β Β  β”‚Β Β  β”œβ”€β”€
    β”‚Β Β  β”‚Β Β  β”œβ”€β”€
    β”‚Β Β  β”‚Β Β  β”œβ”€β”€ index.ts
    β”‚Β Β  β”‚Β Β  β”œβ”€β”€
    β”‚Β Β  β”‚Β Β  β”œβ”€β”€
    β”‚Β Β  β”‚Β Β  └──
    β”‚Β Β  └── index.ts
    β”œβ”€β”€ reducers
    β”‚Β Β  └── book.reducer.ts
    β”œβ”€β”€ routes
    β”‚Β Β  β”œβ”€β”€ book.routes.ts
    β”‚Β Β  └── index.ts
    β”œβ”€β”€ services
    β”‚Β Β  β”œβ”€β”€ book.service.ts
    β”‚Β Β  └── index.ts
    β”œβ”€β”€ translations
    β”‚Β Β  └── es
    β”‚Β Β      β”œβ”€β”€ book.ts
    β”‚Β Β      └── index.ts
    └── utils
        └── book-testing.util.ts


To execute this packages tests, you will need a file named .env.mysql.testing on your root folder like this:



Now go to the package app/Containers/Crud folder and execute:

codecept run functional


CRUD PORTO Containers for apiato and Angular2 modules generator, based on Laravel 5.4 and Angular 2.4+

Crud Info

⭐ Stars 23
πŸ”— Source Code
πŸ•’ Last Update a year ago
πŸ•’ Created 6 years ago
🐞 Open Issues 3
βž— Star-Issue Ratio 8
😎 Author llstarscreamll