Installation
composer require sowork/tlrv dev-master
Register the service provider in config/app.php:
'providers' => [
// ...
Sowork\TLRV\TLRVProvider::class,
],
Publish Assets
php artisan vendor:publish --provider="Sowork\TLRV\TLRVProvider"
This creates the database table (tlrv_nodes), migrations, and frontend assets.
Frontend Setup
npm install || yarn
Register the Vue component in resources/assets/js/app.js:
Vue.component('tlrv-node', require('./components/TLRVNode.vue'));
First Use Case
/tlrv in your browser to preview the admin interface.TLRVNode Eloquent model (likely auto-generated after publishing).use Sowork\TLRV\Models\TLRVNode;
// Get all nodes (flat)
$nodes = TLRVNode::all();
// Get children of a parent (recursive)
$children = TLRVNode::where('parent_id', $parentId)->get();
// Recursive tree traversal (Laravel 8+)
$tree = TLRVNode::with('children')->where('parent_id', null)->get();
with('children') for nested relationships (ensure the model defines children())./tlrv route provides a Vue.js-based UI to manage hierarchical data.resources/views/vendor/tlrv/.@foreach($tree as $node)
<tlrv-node :node="{{ $node }}"></tlrv-node>
@endforeach
props: ['node'],
data() {
return {
children: this.node.children || []
};
}
DatabaseSeeder:
TLRVNode::create([
'uid' => 'root',
'node_value' => 'Root',
'parent_id' => null,
'addition' => json_encode(['meta' => 'data']),
]);
Route::get('/api/tlrv/tree', function () {
return TLRVNode::with('children')->where('parent_id', null)->get();
});
Database Schema Assumptions
tlrv_nodes table with columns:
uid (unique identifier, not auto-increment).node_value (display value).parent_id (foreign key to self).addition (JSON field for metadata).Vue Component Registration
tlrv-node component requires node prop with children nested.node.children errors if data isn’t hierarchical.Recursive Queries
with('children') may hit query limits for deep trees.withDepth() (Laravel 8+) or manual recursion:
$tree = TLRVNode::where('parent_id', null)->get()->each->loadChildren();
UID vs. ID
uid (not Laravel’s default id). Ensure your queries use uid for lookups.DB::enableQueryLog() to inspect recursive queries.tlrv-node props to verify data structure.php artisan tinker
TLRVNode::where('parent_id', 1)->with('children')->get();
Custom Models
Sowork\TLRV\Models\TLRVNode for additional fields:
class CustomTLRVNode extends TLRVNode {
protected $casts = ['addition' => 'array'];
}
Override Views
php artisan vendor:publish --tag=tlrv-views
resources/views/vendor/tlrv/admin.blade.php.Add Validation
TLRVNode model’s rules() in a service provider:
TLRVNode::addGlobalScope('custom', function (Builder $builder) {
$builder->where('node_value', '!=', 'deleted');
});
API Responses
Route::get('/api/tlrv', function () {
return TLRVNode::with('children')->where('parent_id', null)->get()
->map(fn ($node) => $node->toArray());
});
Localization
resources/lang/en/tlrv.php:
return [
'node_value' => 'Custom Label',
];
parent_id and uid in migrations:
$table->index('parent_id');
$table->unique('uid');
$tree = Cache::remember('tlrv-tree', now()->addHours(1), function () {
return TLRVNode::with('children')->where('parent_id', null)->get();
});
/tlrv route in routes/web.php:
Route::middleware(['auth'])->group(function () {
Route::get('/tlrv', [TLRVController::class, 'index']);
});
uid input to prevent injection:
$uid = request()->validate(['uid' => 'required|string|max:255']);
How can I help you explore Laravel packages today?