schoolaid/nadota

Laravel admin panel package for resource-based CRUD interfaces similar to Laravel Nova

1.0.0 2025-08-22 03:15 UTC

This package is auto-updated.

Last update: 2025-08-22 03:17:15 UTC


README

Tests Latest Stable Version License

Para eso, mejor Nadota.

Nadota is a Laravel admin panel package that provides a resource-based CRUD interface similar to Laravel Nova. It allows developers to create administrative interfaces for Eloquent models through resource classes that define how data is displayed, filtered, and manipulated.

Features

  • Resource-based Architecture: Define admin panels through Resource classes
  • Rich Field Types: 10+ field types including Input, Select, DateTime, Toggle, and more
  • Relationship Support: BelongsTo, HasOne relationships with full CRUD support
  • Advanced Filtering: Built-in filtering system with custom filter support
  • Sorting & Searching: Configurable sorting and search capabilities
  • Authorization: Integration with Laravel policies for fine-grained permissions
  • Inertia.js Integration: Seamless SPA experience with Vue 3 frontend
  • Comprehensive Testing: 126 passing tests with extensive coverage

Status

Current Version: v0.2.0 - Feature Enhanced
Test Coverage: 118 passing tests, 0 failures - service integration tests moved to separate directory
Core Features: ✅ Complete field system with all basic and advanced field types
Advanced Features: ✅ Conditional visibility, validation, custom values, and constraints
Service Integration: ⚠️ Authorization interface pending (see MISSING_FEATURES_SPEC.md)

Installation

You can install the package via Composer:

composer require said/nadota

Publish the configuration file:

php artisan vendor:publish --provider="Said\Nadota\NadotaServiceProvider" --tag="config"

Quick Start

1. Create a Resource

Create a resource class for your Eloquent model:

<?php

namespace App\Nadota;

use Said\Nadota\Resource;
use Said\Nadota\Http\Fields\Input;
use Said\Nadota\Http\Fields\Select;
use Said\Nadota\Http\Fields\DateTime;
use Said\Nadota\Http\Fields\Relations\BelongsTo;

class UserResource extends Resource
{
    public string $model = \App\Models\User::class;

    public function fields($request): array
    {
        return [
            Input::make('Name', 'name')
                ->sortable()
                ->searchable()
                ->required(),
                
            Input::make('Email', 'email')
                ->rules(['email', 'unique:users,email'])
                ->sortable()
                ->searchable(),
                
            Select::make('Status', 'status')
                ->options([
                    'active' => 'Active',
                    'inactive' => 'Inactive',
                    'pending' => 'Pending'
                ])
                ->filterable(),
                
            DateTime::make('Created At', 'created_at')
                ->sortable()
                ->exceptOnForms(),
                
            BelongsTo::make('Role', 'role')
                ->relatedModel(\App\Models\Role::class)
                ->relationAttribute('name')
                ->filterable(),
        ];
    }
}

2. Register the Resource

Resources are automatically discovered in the app/Nadota directory, or you can manually register them in your service provider.

3. Access the Admin Panel

Navigate to /resources/users to see your resource in action!

Available Field Types

Basic Fields

  • Input: Text input fields with validation
  • Select: Dropdown selection with options
  • Checkbox: Single checkbox for boolean values
  • Toggle: Toggle switch for boolean values
  • Radio: Radio button groups
  • DateTime: Date/time picker with formatting
  • Hidden: Hidden form fields
  • CheckboxList: Multiple checkbox selections

Relationship Fields

  • BelongsTo: Many-to-one relationships
  • HasOne: One-to-one relationships

Field Configuration

All fields support extensive configuration options:

Input::make('Name', 'name')
    ->label('Full Name')
    ->placeholder('Enter full name')
    ->required()
    ->sortable()
    ->searchable()
    ->filterable()
    ->rules(['min:2', 'max:255'])
    ->default('John Doe')
    ->hideFromIndex()
    ->showOnDetail();

Visibility Control

Control where fields appear:

// Hide from specific views
$field->hideFromIndex()
      ->hideFromDetail()
      ->hideFromCreation()
      ->hideFromUpdate();

// Show only on specific views
$field->onlyOnIndex()
      ->onlyOnDetail()
      ->onlyOnForms()
      ->exceptOnForms();

Validation

Add Laravel validation rules:

Input::make('Email', 'email')
    ->required()
    ->rules(['email', 'unique:users,email'])
    ->nullable(); // When updating

Sorting & Filtering

Make fields sortable and filterable:

Input::make('Name', 'name')
    ->sortable()
    ->searchable()
    ->filterable();

// Custom sort logic
$field->sortable(function ($query, $direction) {
    return $query->orderBy('last_name', $direction)
                 ->orderBy('first_name', $direction);
});

Relationships

BelongsTo Relationships

BelongsTo::make('Category', 'category')
    ->relatedModel(Category::class)
    ->relationAttribute('name')
    ->filterable()
    ->sortable();

HasOne Relationships

HasOne::make('Profile', 'profile')
    ->relatedModel(Profile::class)
    ->relationAttribute('bio')
    ->hideFromIndex();

Authorization

Integrate with Laravel policies:

// In your Resource class
public function authorizedTo($request, string $action, $model = null): bool
{
    return $this->resourceAuthorization
        ->setModel($model ?? $this->model)
        ->authorizedTo($request, $action);
}

Testing

The package includes a comprehensive test suite with 69 passing tests covering core functionality. Run tests with:

# Run all tests
composer test

# Run with coverage
composer test-coverage

# Run specific test file
./vendor/bin/pest tests/Unit/Fields/InputTest.php

Test Structure & Status

Current Status: 118 passing tests, 0 failing tests ✅

The test suite now includes comprehensive coverage:

tests/
├── Unit/
│   └── Fields/
│       ├── InputTest.php ✅ (16 tests)
│       ├── DateTimeTest.php ✅ (11 tests)
│       ├── CheckboxTest.php ✅ (11 tests)
│       ├── ToggleTest.php ✅ (13 tests)
│       ├── SelectTest.php ✅ (12 tests)
│       ├── CheckboxListTest.php ✅ (14 tests)
│       ├── ServiceIntegration/
│       │   ├── Relations/ (moved - requires Laravel app context)
│       │   └── DefaultValueTraitIntegrationTest.php (moved - requires service bindings)
│       └── Traits/
│           ├── SearchableTraitTest.php ✅ (7 tests)
│           ├── VisibilityTraitTest.php ✅ (12 tests)
│           ├── DefaultValueTraitTest.php ✅ (11 tests)
│           └── ValidationTraitTest.php ✅ (13 tests)

Missing Features: See MISSING_FEATURES_SPEC.md for unimplemented methods and advanced functionality.

Configuration

The configuration file allows customization of various aspects:

// config/nadota.php
return [
    'path' => 'said',
    'namespace' => 'said', 
    'path_resources' => 'app/Nadota',
    'middlewares' => ['api'],
    'api' => [
        'prefix' => 'nadota-api'
    ],
    'frontend' => [
        'prefix' => 'resources'
    ],
    'fields' => [
        'text' => [
            'type' => 'text',
            'component' => 'FieldText'
        ],
        // ... other field mappings
    ]
];

API Endpoints

Nadota automatically generates RESTful API endpoints:

  • GET /nadota-api/resources/{resource} - Index with pagination/filtering
  • GET /nadota-api/resources/{resource}/create - Create form data
  • POST /nadota-api/resources/{resource} - Store new resource
  • GET /nadota-api/resources/{resource}/{id} - Show resource
  • GET /nadota-api/resources/{resource}/{id}/edit - Edit form data
  • PUT /nadota-api/resources/{resource}/{id} - Update resource
  • DELETE /nadota-api/resources/{resource}/{id} - Delete resource

Requirements

  • PHP 8.2+ | 8.3+
  • Laravel 11.0+ | 12.0+
  • Inertia.js 2.0+
  • Pest 3.0+ (for testing)

Contributing

Please see CONTRIBUTING.md for details.

Security

If you discover any security-related issues, please email security@said.com instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.

Changelog

Please see CHANGELOG.md for more information on what has changed recently.