Laravel Complaint & Note Manager is a package for managing complaints, notes, and similar entities in Laravel projects. It uses polymorphic relationships for integration with any models.
Ideal for social networks, e-commerce, and content moderation projects that require collecting and managing user complaints, reports, or note (use cases).
- Polymorphic Relationships: Easy integration with different models.
- Metadata: Ability to save additional data.
- Automatic Deletion: Manage outdated records.
- Customization: Configure through configuration files and migrations.
- Laravel Complaint & Note Manager
- Installation
- Configuration
- Usage
- Automatic Deletion of Old Complaints
- Use cases
- Testing
- Want to Contribute?
- License
- PHP ^8.0
- Laravel ^9.0, ^10.0, ^11.0
composer require alyakin/reportingphp artisan vendor:publish --provider="Alyakin\Reporting\ReportingServiceProvider"
php artisan migrateEnsure that your database settings are correct before running migrations.
After installing the module, the configuration file is available at config/reporting.php. If the file is missing, run the following command:
php artisan vendor:publish --provider="Alyakin\Reporting\ReportingServiceProvider" --tag=configExample configuration file content:
return [
'report_model' => \Alyakin\Reporting\Models\Report::class,
'soft_delete_days' => 30,
];If you need to extend the default model, update the report_model parameter in the configuration:
'report_model' => \App\Models\CustomReport::class,The model must extend Alyakin\Reporting\Models\Report:
namespace App\Models;
use Alyakin\Reporting\Models\Report;
class CustomReport extends Report
{
// Your additional methods or fields
}Add the Reportable trait to any model that should support complaints:
use Alyakin\Reporting\Traits\Reportable;
class Post extends Model
{
use Reportable;
}Use the reports() relationship to create a complaint:
$post = Post::find(1);
$user = $request->user();
$report = $post->addReport([
'reason' => 'Спам',
'meta' => ['severity' => 'низкий'],
], $user->id);Retrieve all complaints for a model:
$reports = $post->reports;Retrieve the related model from a complaint:
$post = $report->reportable;Delete a complaint using standard Eloquent methods:
$report->delete();Old complaints are deleted based on the soft_delete_days parameter in the configuration (default is 30 days).
Add the following line to app/Console/Kernel.php:
$schedule->command('model:prune')->daily();Run the cleanup process manually:
php artisan model:pruneHere are five different examples of how this package can be applied across various domains:
- Social Networks: Users can report posts or comments that violate guidelines...
- E-commerce Platforms: Customers can flag products or sellers...
- Content Management Systems (CMS): Readers can report offensive or incorrect content...
- Customer Support Systems: Users can submit complaints linked to their accounts or tickets...
- Educational Platforms: Students can report problems with course materials or instructors...
This package includes a test suite to ensure functionality works as expected. To run the tests:
composer testThe package uses PHPUnit for feature and unit tests. You can run PHPUnit tests specifically with:
./vendor/bin/phpunitWe use Larastan (PHPStan for Laravel) for static code analysis (with level 9):
./vendor/bin/phpstan analyseLaravel Pint is used for code style enforcement:
./vendor/bin/pintThis package is open for community contributions!
You can:
- Explore the open issues to see what's planned
- Pick a task labeled
good first issueorhelp wanted - Suggest a new feature or improvement by opening an issue
- Fork the repository and submit a Pull Request
When contributing to this package, please ensure:
-
Code Style: All code must follow our style guidelines. Run Laravel Pint before submitting:
./vendor/bin/pint
-
Static Analysis: Code must pass Larastan level 9 analysis:
./vendor/bin/phpstan analyse
-
Test Coverage: All new features or bug fixes must include tests.
-
Documentation: Update the README.md and other documentation to reflect any changes in functionality.
-
Feature Branches: Create a feature branch for your changes and submit a pull request against the main branch.
- Add support for Laravel-style events (e.g.
ReportCreated,ReportDeleted) - Artisan command to purge old reports (
reporting:purge)
We welcome contributions, feedback, and ideas! 😊
This package is distributed under the MIT License.