Creating Custom Packages

Creating The Package

Run the command php artisan make:custom-package {vendor}/{package_name} (eg php artisan make:custom-package Fosetico/Accounts)

The new package will be created in the following structure:

  • packages
    • {vendor}
      • {package_name}
        • src
          • Actions
          • Console
            • Commands
          • Controllers
          • Migrations
          • Models
          • Nova
            • Settings
          • Observers
        • routes
          • web.php
          • api.php

Create Migrations

php artisan make:migration {migration_name} --path=packages/{vendor}/{package_name}/database/migrations (eg php artisan make:migration create_my_custom_model --path=packages/fosetico/accounts/database/migrations)

In case the package is already activated in the system run php artisan migrate.

Create Models

php artisan make:custom-model {vendor}/{package_name}/{MyCustomModel} (eg php artisan make:custom-model Fosetico/Accounts/MyCustomModel)

Create custom Privileges/Permissions

php artisan make:custom-policy {vendor}/{package_name}/{MyCustomModel} (eg php artisan make:custom-policy Fosetico/Accounts/MyCustomModel)

php artisan make:custom-policy-all {vendor}/{package_name} (eg php artisan make:custom-policy-all Fosetico/Accounts)

Create Nova Resource

php artisan make:custom-nova-resource {vendor}/{package_name}/{MyCustomNovaResource} (eg php artisan make:custom-nova-resource Fosetico/Accounts/MyCustomModel)

Create Controllers

php artisan make:custom-controller {vendor}/{package_name}/{MyCustomModel} (eg php artisan make:custom-controller Fosetico/Accounts/MyCustomModel)

Route::post('destroy-pickup-group', [PickupGroupController::class, 'destroy']);
Route::post('store-pickup-group', [PickupGroupController::class, 'store']);
Route::post('update-pickup-group/{id}', [PickupGroupController::class, 'update']);
Route::post('show-pickup-group/{id}', [PickupGroupController::class, 'show']);
Route::post('index-pickup-group', [PickupGroupController::class, 'index']);

Create custom Nova Settings

php artisan make:custom-setting {vendor}/{package_name} (eg php artisan make:custom-setting Fosetico/Accounts)

$API_settings = settings(
section: 'package-fosetico-ordering',
env: 'package-fosetico-ordering'
);
$order->order_group_id = isset($API_settings['default_order_group'])?$API_settings['default_order_group']:'';

Install Package in the system

php artisan install:custom-package {vendor}/{package_name} (eg php artisan install:custom-package Fosetico/Accounts)

run composer dump-autoload

Uninstall Package from the system

php artisan uninstall:custom-package {vendor}/{package_name} (eg php artisan uninstall:custom-package Fosetico/Accounts)

Note: When uninstalling a package the database is not affected (no tables are deleted)

Install a Profile

php artisan install:custom-profile {profile} (eshop/jinius)

Did you find this article useful?