rezaghz/laravel-reports
Add reporting to Eloquent models (spam, violence, abuse, drugs, etc.). Mark a User as reporter and any model as reportable via traits/contracts. Simple API to report, remove, or toggle reports, with publishable migrations. Supports Laravel 6–12, PHP 8.2+.
ReportsInterface). This aligns well with Laravel’s dependency injection and service container patterns, making it easy to integrate without disrupting existing architecture.Reports) and Contracts, allowing customization via method overrides (e.g., report(), getReportable(), getReportTypes()). Supports polymorphic relationships (e.g., reports on User, Post, Comment).reports table (columns: reportable_id, reportable_type, user_id, type, status, notes, created_at). Can be extended or overridden.spam, violence). Custom logic for dynamic types (e.g., user-defined categories) may require additional abstraction.type uniqueness, user_id ownership).reports table schema conflict with existing database design? (e.g., custom statuses, additional metadata).php artisan vendor:publish).php artisan migrate).ReportsInterface and Reports trait in target models (e.g., User, Post).use Rezaghz\Laravel\Reports\Traits\Reports;
class Post extends Model
{
use Reports;
// Customize report types if needed
public function getReportTypes(): array
{
return ['spam', 'hate_speech', 'inappropriate_content'];
}
}
POST /reports).public function store(Request $request, Post $post)
{
$post->report($request->user(), $request->type, $request->notes);
return back()->with('success', 'Report submitted!');
}
resources/views/reports/form.blade.php).<form method="POST" action="{{ route('reports.store', $model) }}">
@csrf
<select name="type">
@foreach($model->getReportTypes() as $type)
<option value="{{ $type }}">{{ ucfirst(str_replace('_', ' ', $type)) }}</option>
@endforeach
</select>
<textarea name="notes"></textarea>
<button type="submit">Submit Report</button>
</form>
pending, resolved).$reports = \Rezaghz\Laravel\Reports\Models\Report::with('reportable')->where('status', 'pending')->get();
report.submitted events) to track usage.pending → resolved).$report = \Rezaghz\Laravel\Reports\Models\Report::find(1);
$report->reportable; // Polymorphic relationship
reportable_type, reportable_id, status are indexed.with() to eager-load reportables:
$reports = Report::with('reportable')->get();
pending_reports).How can I help you explore Laravel packages today?