Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

geanruca's avatar

Help with my new package

Hello guys! Thanks for all your support in this community. To be honest this is my first package and I would like to know if can you give me some tips to improve it.

This packages is a validation-ai layer for Eloquent Models, using the trait HasCoherence you can check if the inserted data should be saved or not. The package has an strict mode to block incoherent data and a softmode which only generates logs in the database with warning to keep an eye on that record using a Polymorphic relationship.

https://github.com/geanruca/coherence

Thanks for your help!

0 likes
2 replies
LaryAI's avatar
Level 58

Great job on releasing your first package! Here are some tips and suggestions to help improve your package, based on your description and a quick look at your coherence repository:


1. Documentation

Tip: Good documentation is essential for adoption.

  • README.md: Expand your README with installation instructions, usage examples, configuration options, and explanations of strict vs. soft modes.

  • Example:

    ## Installation
    
    ```bash
    composer require geanruca/coherence
    

    Usage

    use Geanruca\Coherence\Traits\HasCoherence;
    
    class Post extends Model
    {
        use HasCoherence;
    }
    
    
    

2. Configuration

Tip: Allow users to customize behavior via config files.

  • Publishable Config: Provide a config file (config/coherence.php) and publish it in your service provider:
    $this->publishes([
        __DIR__.'/../config/coherence.php' => config_path('coherence.php'),
    ]);
    
  • Options: Let users set default mode (strict/soft), log table name, etc.

3. Events & Extensibility

Tip: Fire Laravel events when incoherent data is detected.

  • Example:
    event(new \Geanruca\Coherence\Events\IncoherentDataDetected($model, $data));
    
  • This allows users to hook into your package and add custom logic.

4. Testing

Tip: Add automated tests to ensure reliability.

  • Use PHPUnit to test strict and soft modes, logging, and trait integration.
  • Example:
    public function test_strict_mode_blocks_incoherent_data()
    {
        // Arrange: create model with HasCoherence and strict mode
        // Act: try to save incoherent data
        // Assert: assert that save fails and data is not persisted
    }
    

5. Laravel Package Best Practices

  • Service Provider: Register your trait, config, and any bindings in a service provider.
  • Auto-discovery: Support Laravel package auto-discovery.
  • PSR-4 Autoloading: Ensure your package uses PSR-4 autoloading in composer.json.

6. Code Quality

  • Type Hints: Use type hints and PHPDoc blocks for better IDE support.
  • Error Handling: Gracefully handle exceptions and provide meaningful error messages.
  • Polymorphic Relationship: Document how users can access the logs via the relationship.

7. Community

  • Issues & PRs: Encourage users to open issues and pull requests.
  • Contributing Guide: Add a CONTRIBUTING.md to help others contribute.

Summary:
Focus on documentation, configuration, extensibility, and testing. These improvements will make your package easier to use and more robust. Keep iterating and listening to user feedback!

If you need help with specific code examples or want a review of a particular file, let me know!

1 like

Please or to participate in this conversation.