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

Ting Laravel Package

ccmbenchmark/ting

Ting is a lightweight Laravel/PHP package from ccmbenchmark that adds simple benchmarking utilities to time and compare code paths. Use it to measure execution duration, collect results, and quickly spot slow sections during local development and profiling.

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation

    composer require ccmbenchmark/ting
    

    Add the service provider to config/app.php under providers:

    Ccmbenchmark\Ting\TingServiceProvider::class,
    
  2. Define a Model Create a model extending Ccmbenchmark\Ting\Datamapper:

    namespace App\Models;
    
    use Ccmbenchmark\Ting\Datamapper;
    
    class User extends Datamapper
    {
        protected $table = 'users';
        protected $primaryKey = 'id';
    }
    
  3. First Use Case: Fetching a Record

    $user = User::find(1);
    // Automatically maps DB row to object properties
    
  4. Configuration Check config/ting.php for default settings (e.g., connection, caching). Override via:

    'default' => [
        'connection' => 'mysql',
        'cache' => true,
    ],
    

Implementation Patterns

Core Workflows

  1. CRUD Operations

    // Create
    $user = new User(['name' => 'John', 'email' => 'john@example.com']);
    $user->save();
    
    // Read
    $users = User::all(); // Collection of models
    $user = User::find(1);
    
    // Update
    $user->name = 'Jane';
    $user->save();
    
    // Delete
    $user->delete();
    
  2. Query Building Use fluent methods (similar to Eloquent):

    $activeUsers = User::where('active', true)->orderBy('name')->get();
    
  3. Relationships (Basic) Define relationships via hasOne, hasMany:

    class Post extends Datamapper
    {
        public function user()
        {
            return $this->hasOne(User::class, 'user_id');
        }
    }
    
  4. Events & Hooks Override lifecycle methods:

    protected static function boot()
    {
        static::creating(function ($model) {
            $model->created_at = now();
        });
    }
    

Integration Tips

  • Hybrid Models: Extend Datamapper alongside Eloquent traits for mixed workflows.
  • Validation: Use Laravel’s FormRequest or Validator before save().
  • Transactions: Wrap operations in DB::transaction() for atomicity.
  • Caching: Enable cache: true in config to reduce DB load for repeated queries.

Gotchas and Tips

Pitfalls

  1. No Built-in Relationship Loading Unlike Eloquent, ting doesn’t auto-load relationships. Use with() explicitly:

    $user = User::with('posts')->find(1);
    
  2. Primary Key Assumptions Assumes $primaryKey is set correctly. Defaults to id, but override if using custom keys.

  3. Mass Assignment Risks No $guarded or $fillable by default. Validate input manually or use traits:

    use Ccmbenchmark\Ting\Concerns\HasFillable;
    
  4. Connection Overrides Config must specify the DB connection. Defaults to Laravel’s default connection.

Debugging

  • Query Logging: Enable Laravel’s query logging (config/database.php) to inspect raw SQL.
  • Model Events: Use static::saved() or static::deleted() for debugging lifecycle hooks.
  • Cache Issues: Clear config cache (php artisan config:clear) if changes to ting.php aren’t reflected.

Extension Points

  1. Custom Query Builder Override newQuery() to inject logic:

    protected function newQuery()
    {
        return parent::newQuery()->where('deleted_at', null);
    }
    
  2. Dynamic Attributes Use getAttribute() and setAttribute() for computed properties:

    public function getFullNameAttribute()
    {
        return "{$this->first_name} {$this->last_name}";
    }
    
  3. Repository Pattern Create a repository class to abstract ting usage:

    class UserRepository {
        public function findActiveUsers()
        {
            return User::where('active', true)->get();
        }
    }
    
  4. Testing Use Mockery to stub Datamapper queries in unit tests:

    $mockUser = Mockery::mock(User::class);
    $mockUser->shouldReceive('find')->andReturn(new User());
    
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.
emuniq/filament-browser-notifications
syriable/filament-translator
hungnm28/livewire-form
wenprise/eloquent
crudly/encrypted
fadion/bouncy
cuci/prototurk-sdk
gos/pubsub-router-bundle
cuci/prototurk-sdk-symfony
clementtalleu/easyadmin-markdown-bundle
codeflextech/permission-manager
karnoweb/livewire-datepicker
sayedenam/sayed-dashboard
milito/query-filter
apiboxsym/user-bundle
apiboxsym/health-check-bundle
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui