Generating Code


The Code Generation is accessible from the Generate Code tab.


Generate Code

Generating Application Base

Any Vemto project has the capability to generate the following file types by default:

  • Migrations
  • Models
  • Factories
  • Seeders
  • Policies

Applications

After adding applications, it is possible to generate the following code for each one:

  • Requests - When disabled, the validation will be generated directly on the controller
  • Controller - The CRUD Controller
  • Tests - Generates the Tests for the application controllers
  • Views - Generates the applications views

{info} It is recommended to run the tests with ./vendor/bin/phpunit inside the project folder after the code generation. It would help you to find bugs or mistakes before starting to implement your own code.

Modules

The following modules are currently available for code generation:

Permissions

When enabled, the "Permissions Module" generates the following code:

  • Installs this awesome permission package from Spatie.be
  • Generates a seeder for basic roles
  • Generates a seeder for basic permissions (all applications)
  • Adds the admin role to the default user (admin@admin.com, password: admin)
  • Generates applications for Roles and Permissions
  • Adds a way to assign roles to the Auth Model CRUD (User by default)

Admin User

By default, Vemto generates a Seeder for an Admin user with the following credentials:

  • Email: admin@admin.com
  • Password: admin

The User model receives a method isSuperAdmin() that is used to check for super-admin capabilities on Policies.


When the permissions module is disabled, a simple array is added to the auth.php file to identify the super-admins:

<?php

return [
    'super_admins' => ['admin@admin.com'],
    // ...
]

If the permissions module is enabled, it adds the following code to the AuthServiceProvider.php to implicitly grant "Super Admin" role all permissions

Gate::before(function ($user, $ability) {
    if ($user->isSuperAdmin()) {
        return true;
    }
});