generated from spatie/package-skeleton-laravel
-
-
Couldn't load subscription status.
- Fork 0
Setup & Configuration
Azizul Hakim edited this page Jun 12, 2025
·
2 revisions
This guide covers basic and advanced configuration options for Laravel Setanjo.
No configuration needed! Works out of the box with:
- Tenancy Mode: Strict (single tenant type)
-
Tenant Model:
App\Models\User - Caching: Disabled
- Validation: Enabled
use Ahs12\Setanjo\Facades\Settings;
// Global settings
Settings::set('app_name', 'My App');
// User-specific settings
$user = User::find(1);
Settings::for($user)->set('theme', 'dark');Perfect for single-model tenancy with a different model:
// config/setanjo.php
return [
'tenancy_mode' => 'strict',
'strict_tenant_model' => App\Models\Company::class,
];Usage:
$company = Company::find(1);
Settings::for($company)->set('plan', 'premium');For complex multi-tenant applications:
// config/setanjo.php
return [
'tenancy_mode' => 'polymorphic',
'allowed_tenant_models' => [
App\Models\User::class,
App\Models\Company::class,
App\Models\Organization::class,
],
];Usage:
$user = User::find(1);
$company = Company::find(1);
Settings::for($user)->set('theme', 'dark');
Settings::for($company)->set('plan', 'enterprise');Publish the configuration file to customize Setanjo:
php artisan vendor:publish --tag="setanjo-config"<?php
// config/setanjo.php
return [
/*
|--------------------------------------------------------------------------
| Repository Driver
|--------------------------------------------------------------------------
*/
'repository' => env('SETANJO_REPOSITORY', 'database'),
/*
|--------------------------------------------------------------------------
| Database Settings
|--------------------------------------------------------------------------
*/
'table' => env('SETANJO_TABLE', 'settings'),
/*
|--------------------------------------------------------------------------
| Tenantable Column Configuration
|--------------------------------------------------------------------------
| Base name for polymorphic columns: {tenantable_column}_type/_id
*/
'tenantable_column' => 'tenantable',
/*
|--------------------------------------------------------------------------
| Tenancy Mode
|--------------------------------------------------------------------------
| 'strict' - Single tenant model type
| 'polymorphic' - Multiple tenant model types
*/
'tenancy_mode' => env('SETANJO_TENANCY_MODE', 'strict'),
/*
|--------------------------------------------------------------------------
| Strict Tenant Model (strict mode only)
|--------------------------------------------------------------------------
*/
'strict_tenant_model' => env('SETANJO_STRICT_TENANT_MODEL', 'App\\Models\\User'),
/*
|--------------------------------------------------------------------------
| Allowed Tenant Models (polymorphic mode only)
|--------------------------------------------------------------------------
*/
'allowed_tenant_models' => [
// App\Models\Company::class,
// App\Models\User::class,
],
/*
|--------------------------------------------------------------------------
| Cache Configuration
|--------------------------------------------------------------------------
*/
'cache' => [
'enabled' => env('SETANJO_CACHE_ENABLED', false),
'store' => env('SETANJO_CACHE_STORE', null), // null = default store
'prefix' => env('SETANJO_CACHE_PREFIX', 'setanjo'),
'ttl' => env('SETANJO_CACHE_TTL', 3600), // 1 hour
],
/*
|--------------------------------------------------------------------------
| Validation
|--------------------------------------------------------------------------
*/
'validation' => [
'enabled' => env('SETANJO_VALIDATION_ENABLED', true),
'throw_exceptions' => env('SETANJO_THROW_EXCEPTIONS', true),
],
/*
|--------------------------------------------------------------------------
| Default Settings
|--------------------------------------------------------------------------
| Installed via: php artisan setanjo:install-defaults
*/
'defaults' => [
'app_name' => [
'value' => 'Laravel Application',
'description' => 'Application name',
],
'maintenance_mode' => [
'value' => false,
'description' => 'Application maintenance mode',
],
],
];Best for applications with a single tenant model type:
'tenancy_mode' => 'strict',
'strict_tenant_model' => App\Models\User::class,Pros:
- Simpler configuration
- Better performance (no model class resolution)
- Type safety for tenant operations
Cons:
- Limited to one tenant model type
- Requires reconfiguration to add new tenant types
Best for complex multi-tenant applications:
'tenancy_mode' => 'polymorphic',
'allowed_tenant_models' => [
App\Models\User::class,
App\Models\Company::class,
App\Models\Organization::class,
],Pros:
- Multiple tenant model types
- Flexible tenant hierarchy
- Perfect for SaaS applications
Cons:
- Slightly more complex setup
- Requires model class specification for some operations
'cache' => [
'enabled' => true,
'store' => 'redis', // or 'file', 'database', etc.
'prefix' => 'myapp_settings',
'ttl' => 7200, // 2 hours
],Redis (Recommended for production):
'cache' => [
'enabled' => true,
'store' => 'redis',
'ttl' => 3600,
],Database Cache:
'cache' => [
'enabled' => true,
'store' => 'database',
'ttl' => 1800,
],File Cache:
'cache' => [
'enabled' => true,
'store' => 'file',
'ttl' => 3600,
],'validation' => [
'enabled' => true, // Validate tenant models
'throw_exceptions' => true, // Throw exceptions on validation failure
],'validation' => [
'enabled' => false,
'throw_exceptions' => false,
],'table' => 'application_settings','tenantable_column' => 'owner', // Creates: owner_type, owner_idSETANJO_CACHE_ENABLED=false
SETANJO_VALIDATION_ENABLED=true
SETANJO_THROW_EXCEPTIONS=trueSETANJO_CACHE_ENABLED=true
SETANJO_CACHE_STORE=redis
SETANJO_CACHE_TTL=7200
SETANJO_VALIDATION_ENABLED=trueSETANJO_CACHE_ENABLED=false
SETANJO_VALIDATION_ENABLED=false
SETANJO_THROW_EXCEPTIONS=false// config/setanjo.php
'defaults' => [
'app_name' => [
'value' => 'My Laravel App',
'description' => 'Application name displayed in header',
],
'user_registration' => [
'value' => true,
'description' => 'Allow new user registration',
],
'api_rate_limit' => [
'value' => 1000,
'description' => 'API requests per hour limit',
],
],# Install defaults (skip existing)
php artisan setanjo:install-defaults
# Force reinstall (overwrite existing)
php artisan setanjo:install-defaults --force// Different connection for settings
'connection' => 'settings_db',// Custom repository implementation
'repository' => 'custom',
// In service provider
$this->app->bind(SettingsRepositoryInterface::class, MyCustomRepository::class);'cache' => [
'enabled' => true,
'store' => 'redis',
'prefix' => 'app_settings',
'ttl' => 86400, // 24 hours for rarely changing settings
],
// Disable validation in production for better performance
'validation' => [
'enabled' => env('APP_ENV') !== 'production',
'throw_exceptions' => true,
],Test your configuration:
php artisan tinker// Test global settings
Settings::set('test_key', 'test_value');
Settings::get('test_key'); // Should return 'test_value'
// Test tenant settings (strict mode)
$user = User::first();
Settings::for($user)->set('user_test', 'user_value');
Settings::for($user)->get('user_test'); // Should return 'user_value'
// Test caching (if enabled)
Settings::set('cache_test', 'cached_value');
// Check your cache store to verify the key exists- API Reference - Learn all available methods
- Type Casting - Understand how data types work
- Commands - Learn about management commands
Made with ❤️ by @AHS12 • © 2025 • MIT Licensed
- Home - Homepage of the wiki
- Installation Guide - Set up Setanjo in your Laravel project
- Setup & Configuration - Configure tenancy modes and basic options
- Quick Start Examples - Get up and running in minutes
- Tenancy Modes - Understanding strict vs polymorphic modes
- Facade API Reference - Complete method documentation
- HasSettings Trait - Uses of HasSrttings trait
- Commands - Artisan commands for management
- Performance Tips - Optimization best practices