christhompsontldr/laraman
Laraman is a Laravel package that generates and serves simple man-style documentation for your app, helping you expose commands, routes, or internal tooling in a familiar CLI-friendly format for quick lookup by developers.
Installation:
composer require christhompsontldr/laraman
Publish the config file:
php artisan vendor:publish --provider="ChrisThompsonTLDR\Laraman\LaramanServiceProvider" --tag="config"
First Use Case:
Generate a CRUD controller for an existing model (e.g., User):
php artisan laraman:make User
This creates:
app/Http/Controllers/UserController.php)routes/web.php)Where to Look First:
config/laraman.php (adjust controller naming, view paths, or route limits).app/Console/Commands/LaramanMakeController.php (customize scaffolding).ChrisThompsonTLDR\Laraman\LaramanServiceProvider (hook into route registration).Scaffolding:
Use the laraman:make command to generate controllers for models:
php artisan laraman:make Post --resource --api
--resource: Generates RESTful routes (index, store, show, etc.).--api: Skips Blade views, assumes API responses (JSON).Customization:
php artisan vendor:publish --tag="laraman-views"
Then modify resources/views/vendor/laraman/ templates.store()) or use traits.Integration with Existing Code:
Route::resource('custom-route', \App\Http\Controllers\CustomController::class);
{!! Form::open() !!}) in views (required dependency).API-Only Workflows: Disable views in config:
'views' => [
'enabled' => false,
],
Then generate API controllers:
php artisan laraman:make Product --api
Batch Operations:
Use the laraman:make command in package.json scripts or CI/CD pipelines to scaffold multiple controllers:
php artisan laraman:make User Post Category
Performance Issues (v2.0.0):
/users). The package dynamically builds routes, which can slow down route caching.LaramanServiceProvider.View Overrides:
php artisan view:clear
resources/views/vendor/laraman/ exists and permissions are correct.Route Conflicts:
/{model} (e.g., /users). Conflict with existing routes? Use --prefix in config:
'route_prefix' => 'admin',
Now routes appear under /admin/users.Dependency on Laravel Collective:
laravelcollective/html, Laraman’s views will break. Either:
{!! Form::... !!} with Blade syntax in templates.Controller Naming:
{Model}Controller (e.g., UserController). To customize:
'controller_name' => 'Admin{Model}Controller',
Now generates AdminUserController.Check Route Registration: Dump registered routes to debug conflicts:
Route::get('/debug-routes', function() {
dd(Route::getRoutes()->getByName());
});
Log Controller Generation:
Enable debug mode in config/laraman.php:
'debug' => true,
Logs will appear in storage/logs/laraman.log.
Override Route Middleware:
Add middleware to all Laraman routes in LaramanServiceProvider:
public function boot()
{
Route::group(['middleware' => ['auth']], function() {
Route::resource('{model}', \App\Http\Controllers\{Model}Controller::class);
});
}
Custom Fields:
Extend the laraman:make command to include additional fields (e.g., soft deletes):
// app/Console/Commands/LaramanMakeController.php
protected function getStub()
{
if ($this->option('soft-deletes')) {
return __DIR__.'/stubs/controller.soft-deletes.stub';
}
return __DIR__.'/stubs/controller.stub';
}
Then use:
php artisan laraman:make User --soft-deletes
Dynamic Views: Use Blade directives to inject dynamic content:
// In a Laraman view (e.g., resources/views/vendor/laraman/index.blade.php)
@laramanField('custom_field', 'This is dynamic!')
Register the directive in a service provider:
Blade::directive('laramanField', function($expression) {
return "<?php echo \$laramanField = {$expression}; ?>";
});
API Response Customization:
Override the respondWith() method in generated controllers:
// app/Http/Controllers/UserController.php
protected function respondWith($resource)
{
return response()->json([
'data' => $resource,
'custom_meta' => 'value',
]);
}
Hook into Model Events: Use Laraman’s controller stubs to add model observers or events:
// In the generated controller's constructor
public function __construct()
{
$this->model->observe(\App\Observers\UserObserver::class);
}
How can I help you explore Laravel packages today?