-
-
Couldn't load subscription status.
- Fork 0
Installation
This guide will walk you through installing and setting up Laravel Setanjo in your Laravel application.
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
Install the package using Composer:
composer require ahs12/laravel-setanjophp artisan vendor:publish --tag="setanjo-migrations"This creates a migration file in your database/migrations directory:
create_setanjo_settings_table.php
php artisan migrateThis 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)
);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
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"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=trueLaravel Setanjo supports Laravel's package auto-discovery. The service provider and facades are automatically registered when you install the package.
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,
],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 migrateClass not found errors
# Clear and regenerate autoload files
composer dump-autoload
# Clear Laravel caches
php artisan config:clear
php artisan cache:clearPermission denied on database
# Ensure your database user has proper permissions
GRANT ALL PRIVILEGES ON your_database.* TO 'your_user'@'localhost';# Check if tables exist
php artisan tinker
>>> \Schema::hasTable('settings')
=> true
# Test basic functionality
>>> Settings::set('test', 'value')
>>> Settings::get('test')
=> "value"After installation:
- Setup & Configuration - Configure tenancy modes and basic options
- Quick Start - Learn basic usage patterns
- API Reference - Explore all available methods
To update Laravel Setanjo to the latest version:
composer update ahs12/laravel-setanjoAlways check the Changelog for breaking changes before updating.
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