1. Go to this page and download the library: Download tinymvc/orbit library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
tinymvc / orbit example snippets
namespace App\Http\Resources;
use App\Models\Product;
use App\Modules\Bread\Form;
use App\Modules\Bread\Resource;
use App\Modules\Bread\Table;
class ProductsResource extends Resource
{
// ─── Core ───────────────────────────────────────────────────────────
/** The Eloquent model this resource manages */
protected static string $model = Product::class;
/** Singular display name (shown in forms, flash messages) */
protected static string $name = 'Product';
/** URL slug — the resource will be accessible at /admin/products */
protected static string $slug = 'products';
/** Page title (defaults to pluralized $name if omitted) */
protected static null|string $title = 'Products';
/** Description shown below the page title */
protected static null|string $description = 'Manage your product catalog.';
/** Relationships to eager-load on the index query */
protected static array $with = ['category:id,name'];
/** Columns searchable via the search input */
protected static array $searchable = ['name', 'sku', 'description'];
/** Default sort column and direction */
protected static string $orderBy = 'id';
protected static string $orderDirection = 'desc';
// ─── Drawer / Sheet ─────────────────────────────────────────────────
/** Create/edit drawer width: sm | md | lg | xl | 2xl */
protected static string $drawerWidth = 'lg';
// ─── Disabled Features ──────────────────────────────────────────────
/** Disable specific features: "search", "columns", "add_record" */
protected static array $disabled = [];
// ... fields(), columns(), etc.
}
Form\TextInput::make('name')
->label('Display Name') // Field label
->placeholder('Enter name...') // Placeholder text
->umnSpan(2) // Span 2 columns (full-width in 2-col grid)
->fullWidth() // Alias for columnSpan(2)
->disabled() // Render as read-only
->createOnly() // Only show on create form
->editOnly() // Only show on edit form
->hidden() // Don't render (but
// Simple text
Form\TextInput::make('name')->il()->sword()->c()->min(0)->max(99999)->step(0.01)
// With uniqueness validation
Form\TextInput::make('email')->email()->unique('users,email')
Form\SlugInput::make('slug')
->from('title') // Source field to generate slug from
->unique('posts,slug') // Uniqueness validation (table,column)
->maxLength(255)
// Date only
Form\DatePicker::make('published_at')
// Date + Time
Form\DatePicker::make('scheduled_at')
->withTime()
->disablePastDates()
// Disable future dates
Form\DatePicker::make('birth_date')
->disableFutureDates()
Form\FileUpload::make('thumbnail')
->uploadTo('posts') // Upload directory (relative to storage/uploads/)
->acceptedTypes(['jpg', 'png', 'webp']) // Allowed extensions
->maxFileSize(4096) // Max size in KB (4MB)
->compress(80) // JPEG/WebP quality (1-100)
->resize(1200, 800) // Max width × height
->multiple() // Allow multiple files
public static function bulkActions(): array
{
return [
// Status change actions (auto-updates the 'status' column)
Table\BulkAction::make('published')->label('Publish Selected'),
Table\BulkAction::make('draft')->label('Move to Draft'),
Table\BulkAction::make('archived')->label('Archive Selected'),
// Delete action (built-in, handles file cleanup)
Table\BulkAction::make('delete')->label('Delete Selected')->destructive(),
// Custom callback action
Table\BulkAction::make('export')
->label('Export Selected')
->callback(function (array $ids) {
// Custom logic here
}),
// Custom status column
Table\BulkAction::make('inactive')
->label('Deactivate')
->statusColumn('is_active'),
];
}
public static function handleBulkAction(string $action, array $ids)
{
if ($action === 'export') {
// ... custom logic
return inertia()->back()->with('success', 'Exported!');
}
return null; // Fall through to default handling
}
// Mutate data before creating a new record
public static function mutateBeforeCreate(array $data): array
{
$data['user_id'] = auth()->id();
return $data;
}
// Called after a record is created
public static function afterCreate($record, array $data): void
{
// Send notification, dispatch job, etc.
}
// Mutate data before updating
public static function mutateBeforeUpdate(array $data, $record): array
{
if (empty($data['published_at'])) {
unset($data['published_at']);
}
return $data;
}
// Called after a record is updated
public static function afterUpdate($record, array $data): void {}
// Called before a record is deleted
public static function beforeDelete($record): void {}
// Custom validation rules (return null to auto-generate from fields)
public static function storeRules(): null|array
{
return [
'name' => '
use App\Modules\Dashboard\Stats;
Stats::make('Total Revenue')
->value('$1,250.00') // Display value (formatted string)
->change(12.5) // Percentage change
->trend('up') // 'up' | 'down' | 'neutral'
->footer('Trending up this month')
->description('Revenue for the last 6 months');
use App\Modules\Dashboard\Charts\BarChart;
BarChart::make('Monthly Revenue')
->description('Revenue vs Expenses') // Subtitle
->xAxisKey('month') // Category axis key
->dataKeys(['revenue', 'expenses']) // Data series keys
->colors([ // Colors per series
'hsl(221, 83%, 53%)',
'hsl(0, 84%, 60%)',
])
->colSpan(2) // Grid columns to span (1-3)
->height(350) // Chart height in pixels
->data([ // Data array
['month' => 'Jan', 'revenue' => 4000, 'expenses' => 2400],
['month' => 'Feb', 'revenue' => 3000, 'expenses' => 1398],
['month' => 'Mar', 'revenue' => 5000, 'expenses' => 3800],
]);