Skip to content

Configuration

Sajmir Doko edited this page Oct 31, 2025 · 3 revisions

Configuration Guide

The TallPress - Laravel Blog Package offers extensive configuration options through both a static configuration file and a dynamic settings system.

Configuration File

The main configuration file is located at config/tallpress.php after publishing.

Basic Settings

return [
    // Posts per page in listings
    'per_page' => 15,
    
    // Your application's User model
    'author_model' => 'App\\Models\\User',
    
    // Storage disk for images (public, s3, etc.)
    'storage_disk' => 'public',
    
    // Route prefix for public blog
    'route_prefix' => 'blog',
    
    // Admin route prefix
    'admin_route_prefix' => 'admin/blog',
];

Middleware Configuration

'middleware' => [
    'web' => ['web'],
    'api' => ['api'],
    'admin' => ['web', 'auth'],
],

Customize middleware stacks for different route groups.

Search Configuration

'search' => [
    'enabled' => true,
    'fields' => ['title', 'excerpt', 'body'],
],

Control which fields are searchable and enable/disable search functionality.

Comments Configuration

'comments' => [
    'enabled' => true,
    'require_approval' => true,
],
  • enabled: Turn comments on/off globally
  • require_approval: If true, comments need admin approval before appearing

Image Configuration

'images' => [
    'max_size' => 2048,  // Maximum size in KB
    'allowed_mimes' => ['jpg', 'jpeg', 'png', 'gif', 'webp'],
    'path' => 'tallpress/images',
    'organize_by_date' => true,  // Store in year/month folders
],

Hierarchical Storage:

When organize_by_date is true, images are stored as:

tallpress/images/
├── 2024/
│   ├── 01/
│   │   └── image.jpg
│   └── 10/
│       └── photo.png

Editor Configuration

'editor' => [
    'type' => 'rich',  // 'rich' for WYSIWYG, 'markdown' for textarea
    'sanitize_html' => true,
],

HTML Sanitization:

Configure allowed HTML tags and attributes:

'html_purifier' => [
    'HTML.Allowed' => 'p,br,strong,em,u,s,a[href|title|target],ul,ol,li,blockquote,code,pre,h1,h2,h3,h4,h5,h6,img[src|alt|width|height]',
    'HTML.AllowedAttributes' => 'href,title,target,src,alt,width,height',
    'HTML.TargetBlank' => true,
    'AutoFormat.RemoveEmpty' => true,
],

Revisions Configuration

'revisions' => [
    'enabled' => true,
    'keep_revisions' => 10,  // Number of revisions to keep per post
],

When a post is updated, old versions are automatically saved. Older revisions are pruned when the limit is reached.

Activity Logging

'activity_log' => [
    'enabled' => true,
    'keep_days' => 90,  // Days to keep activity logs
],

Tracks all admin actions. Logs older than keep_days are automatically cleaned up.

Role Configuration

'roles' => [
    'add_role_field' => true,   // Add role column to users table
    'role_field' => 'role',
    'default_role' => 'author',
],

Built-in Role System:

If add_role_field is true:

  • Migration adds a role column to users table
  • Three roles: admin, editor, author
  • Works out of the box

External ACL Systems:

If you use Spatie Permission, Bouncer, etc., set add_role_field to false:

'roles' => [
    'add_role_field' => false,
],

Then define the gate in your AppServiceProvider:

use Illuminate\Support\Facades\Gate;

Gate::define('access-tallpress-admin', function ($user) {
    return $user->hasRole(['admin', 'editor', 'author']);
});

Dynamic Settings System

In addition to the config file, the package includes a dynamic settings manager accessible at /admin/blog/settings.

Admin Settings Interface

Configure blog settings without editing files:

General Settings:

  • Posts per page
  • Route prefixes

Search Settings:

  • Enable/disable search
  • Searchable fields

Comments:

  • Enable comments
  • Require approval

Images:

  • Max upload size
  • Allowed formats
  • Organization structure

Editor:

  • Editor type (Rich Text vs Markdown)
  • HTML sanitization

Revisions:

  • Enable versioning
  • Retention limits

Activity Log:

  • Enable logging
  • Retention period

Using Settings Programmatically

use Sajdoko\TallPress\Services\SettingsService;
use Sajdoko\TallPress\Facades\Settings;

// Get a setting (with fallback to config)
$perPage = Settings::get('per_page', 15);

// Set a setting
Settings::set('per_page', 20, 'integer', 'general');

// Set multiple settings
Settings::setMany([
    'comments_enabled' => [
        'value' => true,
        'type' => 'boolean',
        'group' => 'comments'
    ],
    'images_max_size' => [
        'value' => 3072,
        'type' => 'integer',
        'group' => 'images'
    ],
]);

// Get all settings by group
$commentSettings = Settings::getGroup('comments');

// Check if a setting exists
if (Settings::has('per_page')) {
    // Setting exists
}

// Delete a setting
Settings::forget('custom_setting');

Settings Precedence

Settings are checked in this order:

  1. Database settings (from tallpress_settings table)
  2. Config file (config/tallpress.php)
  3. Default value (passed to get() method)

This allows runtime configuration while maintaining fallbacks.

Artisan Commands

Initialize settings from config:

php artisan tallpress:init-settings

Force overwrite existing settings:

php artisan tallpress:init-settings --force

The tallpress:install command automatically initializes settings.

Environment-Specific Configuration

Use .env file for environment-specific values:

BLOG_PER_PAGE=20
BLOG_ROUTE_PREFIX=articles
BLOG_STORAGE_DISK=s3

Then reference in config/tallpress.php:

'per_page' => env('BLOG_PER_PAGE', 15),
'route_prefix' => env('BLOG_ROUTE_PREFIX', 'blog'),
'storage_disk' => env('BLOG_STORAGE_DISK', 'public'),

Storage Configuration

Using Amazon S3

  1. Install S3 driver:
composer require league/flysystem-aws-s3-v3
  1. Configure in .env:
BLOG_STORAGE_DISK=s3
AWS_ACCESS_KEY_ID=your-key
AWS_SECRET_ACCESS_KEY=your-secret
AWS_DEFAULT_REGION=us-east-1
AWS_BUCKET=your-bucket
  1. Update config:
'storage_disk' => env('BLOG_STORAGE_DISK', 's3'),

Custom Storage Disks

Define custom disk in config/filesystems.php:

'disks' => [
    'tallpress' => [
        'driver' => 'local',
        'root' => storage_path('app/tallpress'),
        'url' => env('APP_URL').'/storage/tallpress',
        'visibility' => 'public',
    ],
],

Then use in tallpress config:

'storage_disk' => 'tallpress',

Localization

Publishing Language Files

php artisan vendor:publish --tag=tallpress-lang

Adding Translations

After publishing, edit resources/lang/vendor/tallpress/{locale}/messages.php:

return [
    'posts' => 'Posts',
    'create_post' => 'Create Post',
    'edit_post' => 'Edit Post',
    // Add more translations
];

Changing Default Locale

In your config/app.php:

'locale' => 'es',  // Spanish
'fallback_locale' => 'en',

Advanced Configuration

Custom Routes

Disable package routes and define your own:

// config/tallpress.php
'register_routes' => false,

Then in your routes/web.php:

use Sajdoko\TallPress\Http\Controllers\PostController;

Route::prefix('articles')->group(function () {
    Route::get('/', [PostController::class, 'index']);
    Route::get('/{slug}', [PostController::class, 'show']);
});

Custom Policies

Override policy methods in your AuthServiceProvider:

use Sajdoko\TallPress\Models\Post;
use App\Policies\CustomPostPolicy;

protected $policies = [
    Post::class => CustomPostPolicy::class,
];

Custom Observers

Add custom logic to post events:

use Sajdoko\TallPress\Models\Post;
use App\Observers\CustomPostObserver;

// In AppServiceProvider boot method
Post::observe(CustomPostObserver::class);

Configuration Best Practices

  1. Keep sensitive data in .env - Never commit credentials
  2. Use dynamic settings for runtime changes - Edit via admin UI
  3. Cache config in production - Run php artisan config:cache
  4. Document custom changes - Comment your modifications
  5. Test after changes - Verify functionality after configuration updates

Next: Learn how to use the tallpress → Usage Guide

Clone this wiki locally