Installation
composer require vokhoalab/code-review
Publish the config file (if available) and run migrations:
php artisan vendor:publish --provider="Vokhoalab\CodeReview\CodeReviewServiceProvider"
php artisan migrate
First Use Case: Reviewing a Pull Request
CodeReview facade to create a review:
use Vokhoalab\CodeReview\Facades\CodeReview;
$review = CodeReview::create([
'pull_request_id' => 123,
'user_id' => auth()->id(),
'comments' => ['file1.php' => ['line 10: Fix this typo']],
'status' => 'approved', // or 'changes_requested', 'commented'
]);
$review->addComment('file2.php', 20, 'Improve this logic');
Key Classes to Explore
Vokhoalab\CodeReview\Models\Review – Core model for storing reviews.Vokhoalab\CodeReview\Models\Comment – Stores inline/file comments.Vokhoalab\CodeReview\Services\ReviewService – Business logic for reviews.// routes/web.php
Route::post('/github-webhook', [CodeReviewWebhookController::class, 'handle']);
CodeReview::generateTemplate() method to scaffold common review patterns:
$template = CodeReview::generateTemplate('backend-auth');
$review = $template->fill(['user_id' => auth()->id()]);
$review->save();
CodeReview::batch() method to process multiple PRs:
$reviews = CodeReview::batch([
['pull_request_id' => 1, 'user_id' => 1, 'status' => 'approved'],
['pull_request_id' => 2, 'user_id' => 2, 'status' => 'changes_requested'],
]);
CodeReviewResource to visualize reviews in the admin panel:
namespace App\Nova;
use Vokhoalab\CodeReview\Models\Review;
use Laravel\Nova\Resource;
class CodeReviewResource extends Resource
{
public static $model = Review::class;
// Define fields, filters, and actions here
}
approved, changes_requested, commented) by extending the Review model:
namespace App\Models;
use Vokhoalab\CodeReview\Models\Review as BaseReview;
class Review extends BaseReview
{
protected $casts = [
'status' => 'string',
];
public static $statuses = [
'approved',
'needs_revision',
'under_review',
'rejected',
];
}
Missing Webhook Configuration
php artisan code-review:test-webhook (if available)..env.Database Schema Mismatches
reviews, comments). Customize via config:
'tables' => [
'reviews' => 'custom_reviews',
'comments' => 'custom_comments',
],
php artisan vendor:publish --tag=code-review-migrations to update migrations.Permission Issues
public function handle()
{
$this->authorize('review', $pullRequest);
// ...
}
Log Review Events
Enable debug logging in config/code-review.php:
'debug' => env('CODE_REVIEW_DEBUG', false),
Check storage/logs/laravel.log for webhook payloads.
Validate Webhook Payloads
Use dd($request->all()) in the webhook controller to inspect raw data.
Custom Comment Types
Extend the Comment model to add metadata (e.g., severity, type):
namespace App\Models;
use Vokhoalab\CodeReview\Models\Comment as BaseComment;
class Comment extends BaseComment
{
protected $casts = [
'severity' => 'string', // 'low', 'medium', 'high'
];
}
Slack/Email Notifications
Hook into the review.created event to send alerts:
// Event listener
public function handle(ReviewCreated $event)
{
Notification::route('slack', config('services.slack.webhook'))
->notify(new ReviewApproved($event->review));
}
API Endpoints for Frontend Expose reviews via API:
Route::get('/reviews/{pr_id}', [CodeReviewController::class, 'show']);
Use CodeReview::findByPrId($pr_id) to fetch reviews.
$reviews = Review::with('comments.user')->get();
$template = Cache::remember("review_template_{$templateName}", now()->addHours(1), function () {
return CodeReview::generateTemplate($templateName);
});
How can I help you explore Laravel packages today?