Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Database Laravel Package

wp-starter/database

Database layer for wp-starter projects, providing a simple foundation for configuring and working with WordPress/MySQL connections, queries, and migrations in PHP. Designed to integrate cleanly with the wp-starter ecosystem.

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation

    composer require wp-starter/database
    

    Publish the package config (if applicable):

    php artisan vendor:publish --provider="WpStarter\Database\DatabaseServiceProvider"
    
  2. Configuration Check config/wpstarter-database.php for default settings. Key entries:

    'connections' => [
        'mysql' => [
            'driver' => 'mysql',
            'host' => env('DB_HOST', '127.0.0.1'),
            // ... other standard Laravel DB config
        ],
    ],
    
  3. First Use Case Use the facade or service container to interact with the database:

    use WpStarter\Database\Facades\Database;
    
    // Query example
    $users = Database::table('users')->where('active', 1)->get();
    

Implementation Patterns

Core Workflows

  1. Database Abstraction

    • Use the package’s facade (Database) for consistent queries across projects.
    • Example: Replace raw Eloquent calls with:
      $posts = Database::table('posts')->where('status', 'published')->paginate(10);
      
  2. Schema Management

    • Migrations: Extend Laravel’s Schema builder via the package’s helpers:
      use WpStarter\Database\Schema;
      
      Schema::create('wp_options', function (Blueprint $table) {
          $table->string('option_name')->unique();
          $table->text('option_value');
      });
      
  3. Query Building

    • Chain methods for dynamic queries:
      $results = Database::table('products')
          ->where('price', '>', 100)
          ->orderBy('created_at', 'desc')
          ->limit(5)
          ->get();
      
  4. WordPress-Specific Queries

    • If the package includes WP helpers (e.g., wp_get_posts wrapper), use:
      $posts = Database::wp()->getPosts(['post_type' => 'product', 'numberposts' => 5]);
      

Integration Tips

  • Laravel Mixins: Extend the package’s query builder with custom methods:

    Database::extend(function ($builder) {
        $builder->macro('active', function () {
            return $this->where('status', 'active');
        });
    });
    

    Usage:

    $activeUsers = Database::table('users')->active()->get();
    
  • Event Listeners: Hook into database events (e.g., eloquent.saved) via Laravel’s event system.


Gotchas and Tips

Pitfalls

  1. Namespace Collisions

    • If the package uses DB facade, avoid conflicts by aliasing:
      'aliases' => [
          'DB' => WpStarter\Database\Facades\Database::class,
      ],
      
  2. Missing WP-Specific Docs

    • The package may lack WordPress-specific documentation. Cross-reference with Laravel’s DB docs and WP’s wpdb class.
  3. Schema Differences

    • WordPress tables (e.g., wp_posts) may require custom blueprints. Example:
      Schema::create('wp_posts', function (Blueprint $table) {
          $table->bigIncrements('ID'); // WP uses bigint for IDs
          $table->string('post_title', 255);
          // ... other WP-specific columns
      });
      

Debugging

  • Query Logging: Enable Laravel’s query logging:

    DB::enableQueryLog();
    $results = Database::table('users')->get();
    dd(DB::getQueryLog());
    
  • Connection Issues: Verify .env and config/wpstarter-database.php match:

    DB_CONNECTION=wpstarter_mysql
    

Extension Points

  1. Custom Connections Add a new connection in config/wpstarter-database.php:

    'connections' => [
        'wp_remote' => [
            'driver' => 'mysql',
            'host' => env('WP_REMOTE_HOST'),
            // ...
        ],
    ],
    
  2. Query Observers Attach observers to models for pre/post hooks:

    Database::observe(User::class, function ($model) {
        // Logic before/after save
    });
    
  3. Seeding Use Laravel’s seeder classes with the package’s facade:

    public function run()
    {
        Database::table('users')->insert([
            ['name' => 'Admin', 'email' => 'admin@example.com'],
        ]);
    }
    
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
terminal42/code-quality-tools
codifyo/ts-generator-bundle
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky