Skip to content

Installation

Azizul Hakim edited this page Jun 12, 2025 · 3 revisions

This guide will walk you through installing and setting up Laravel Setanjo in your Laravel application.

Requirements

Before installing Laravel Setanjo, ensure your system meets these requirements:

  • PHP: 8.2 or higher
  • Laravel: 10.0, 11.0, or 12.0
  • Database: MySQL, PostgreSQL, SQLite, or SQL Server

Step 1: Install via Composer

Install the package using Composer:

composer require ahs12/laravel-setanjo

Step 2: Publish and Run Migrations

Publish Migration Files

php artisan vendor:publish --tag="setanjo-migrations"

This creates a migration file in your database/migrations directory:

  • create_setanjo_settings_table.php

Run the Migration

php artisan migrate

This creates the settings table (or your configured table name) with the following structure:

CREATE TABLE settings (
    id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
    key VARCHAR(191) NOT NULL,
    value LONGTEXT NULL,
    description TEXT NULL,
    type VARCHAR(10) DEFAULT 'string',
    tenantable_type VARCHAR(255) NULL,
    tenantable_id BIGINT UNSIGNED NULL,
    created_at TIMESTAMP NULL,
    updated_at TIMESTAMP NULL,
    
    INDEX idx_settings_key (key),
    INDEX idx_settings_tenant_key (tenantable_type, tenantable_id, key),
    UNIQUE KEY settings_key_tenant_unique (key, tenantable_type, tenantable_id)
);

Step 3: Publish Configuration (Optional)

For basic usage with the default User model, no configuration is needed. For advanced setups:

php artisan vendor:publish --tag="setanjo-config"

This publishes config/setanjo.php where you can customize:

  • Tenancy mode (strict/polymorphic)
  • Allowed tenant models
  • Caching settings
  • Validation options

Step 4: Verify Installation

Test your installation with a simple example:

use Ahs12\Setanjo\Facades\Settings;

// Set a global setting
Settings::set('app_name', 'My Laravel App');

// Retrieve it
$appName = Settings::get('app_name');
echo $appName; // "My Laravel App"

Environment Configuration

Environment Variables

You can configure Setanjo using environment variables in your .env file:

# Repository driver (currently only 'database' supported)
SETANJO_REPOSITORY=database

# Table name for storing settings
SETANJO_TABLE=settings

# Tenancy mode: 'strict' or 'polymorphic'
SETANJO_TENANCY_MODE=strict

# Strict mode tenant model (when using strict mode)
SETANJO_STRICT_TENANT_MODEL="App\Models\User"

# Caching configuration
SETANJO_CACHE_ENABLED=true
SETANJO_CACHE_STORE=redis
SETANJO_CACHE_PREFIX=setanjo
SETANJO_CACHE_TTL=3600

# Validation settings
SETANJO_VALIDATION_ENABLED=true
SETANJO_THROW_EXCEPTIONS=true

Package Auto-Discovery

Laravel Setanjo supports Laravel's package auto-discovery. The service provider and facades are automatically registered when you install the package.

Manual Registration (if needed)

If auto-discovery is disabled, manually register the service provider in config/app.php:

'providers' => [
    // Other providers...
    Ahs12\Setanjo\SetanjoServiceProvider::class,
],

'aliases' => [
    // Other aliases...
    'Settings' => Ahs12\Setanjo\Facades\Settings::class,
],

Troubleshooting

Common Issues

Migration fails with "table already exists"

# Check if migration was already run
php artisan migrate:status

# If needed, rollback and re-run
php artisan migrate:rollback --step=1
php artisan migrate

Class not found errors

# Clear and regenerate autoload files
composer dump-autoload

# Clear Laravel caches
php artisan config:clear
php artisan cache:clear

Permission denied on database

# Ensure your database user has proper permissions
GRANT ALL PRIVILEGES ON your_database.* TO 'your_user'@'localhost';

Verification Commands

# Check if tables exist
php artisan tinker
>>> \Schema::hasTable('settings')
=> true

# Test basic functionality
>>> Settings::set('test', 'value')
>>> Settings::get('test')
=> "value"

Next Steps

After installation:

  1. Setup & Configuration - Configure tenancy modes and basic options
  2. Quick Start - Learn basic usage patterns
  3. API Reference - Explore all available methods

Updating

To update Laravel Setanjo to the latest version:

composer update ahs12/laravel-setanjo

Always check the Changelog for breaking changes before updating.

📚 Documentation Structure

Home

  • Home - Homepage of the wiki

Getting Started

Core Concepts

API Reference

Advanced Usage

  • Commands - Artisan commands for management

Tips

🤝 Community

Clone this wiki locally