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
  • Routes
  • API Routes
  • API Auth with Laravel Sanctum

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 and API (if enabled)
  • Views - Generates the applications views
  • API - Generates the API files (controllers and resources)

{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 ([email protected], password: admin)
  • Generates applications for Roles and Permissions
  • Adds a way to assign roles to the Auth Model CRUD (User by default)

Permissions - API Endpoints

When enabled, the "Permissions - API Endpoints 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 ([email protected], password: admin)
  • Generates endpoints for Roles and Permissions
  • Adds a way to assign roles to the Auth Model (User by default) on the create/update endpoints (by sending an array of permissions or roles IDs on the roles/permissions attribute)

Auth Scaffold

When enabled, the "Auth Scaffold module" will generate the application basic scaffold using the UI template chosen on project creation (Laravel UI, Jetstream, or Breeze).

Admin User

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

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' => ['[email protected]'],
    // ...
]

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;
    }
});