permafrost-dev/code-snippets
Laravel package for managing reusable code snippets: create, organize, tag, and quickly retrieve snippets for your projects. Includes an admin UI, storage/database support, and tools to share or reuse snippets across teams and environments.
highlight_string or third-party libraries like vlucas/phpdotenv for config).LIKE queries; advanced search would require customization).WHERE clauses on tags).laravel-activitylog), or self-built solutions (e.g., using Laravel Filesystem + database).tsvector) if search is critical.composer require permafrost-dev/code-snippets).php artisan vendor:publish --tag="snippets-migrations") and run them.use App\Models\Snippet;
$snippet = Snippet::create(['title' => 'Test', 'code' => '<?php echo "Hello"; ?>']);
Snippet model (e.g., add user_id for ownership):
php artisan make:model SnippetExtension --extend=App\Models\Snippet
php artisan make:controller SnippetController --resource --api
routes/api.php:
Route::apiResource('snippets', \App\Http\Controllers\SnippetController::class);
use statements for new Eloquent features).Str::camel() → Str::of()).pdo, mbstring, and tokenizer (for syntax highlighting) are enabled.namespace App\Services;
class SnippetService {
public function __construct(private \Permafrost\Snippets\Models\Snippet $snippetModel) {}
public function getSnippet(int $id) { ... }
}
composer.json to avoid surprises:
"require": {
"permafrost-dev/code-snippets": "1.0.0"
}
README.md in your repo with:
## Customization
Override the snippet model by publishing it:
```bash
php artisan vendor:publish --tag="snippets-models"
title, tags, and created_at.created_at if snippet volume exceeds 1M.Cache::remember("snippets:tag:{$tag}", now()->addHours(1), fn() => Snippet::whereTag($tag)->get());
| Failure | Impact | Mitigation |
|---|---|---|
| Package deprecation | Broken snippets, no updates | Fork and maintain; migrate to alternative. |
| Database corruption | Lost snippets | Regular backups; transactional writes. |
| Syntax highlighting fail | Broken UI rendering | Fallback to plain text; log errors. |
| High traffic | Slow queries | Query caching; read replicas. |
| Auth bypass | Unauthorized snippet access | Strict middleware; audit logs. |
php artisan snippets:install if added).How can I help you explore Laravel packages today?