Skip to main content

Nice to Have Features

This document provides an overview of extra features and utilities available in the codebase that can enhance your development experience.

Exception Handling

HandlesException Trait

A flexible trait for controlling exception behavior in your classes.
use Inly\Core\Support\Traits\HandlesException;

class MyService
{
    use HandlesException;

    public function riskyOperation()
    {
        foreach($orders as $order) {
            try {
                // Some risky operation
                $order->fullfill();
            } catch (Exception $e) {
                $this->handleException($e);
            }
        }
    }
}
Key Methods:
  • throwOnException() - Always throw exceptions (default)
  • continueOnException() - Continue execution without throwing
  • shouldThrow(bool) - Conditionally control throwing behavior
  • beforeException(Closure) - Execute callback before handling exception
Usage Examples:
// Always throw
$service->throwOnException()->riskyOperation();

// Continue on error
$service->continueOnException()->riskyOperation();

// Conditional throwing
$service->shouldThrow($debugMode)->riskyOperation();

// Custom pre-handling
$service->beforeException(fn($e) => Log::error($e->getMessage()))
       ->riskyOperation();

Conditional Logic

Laravel Conditionable Trait

Leverage Laravel’s built-in Conditionable trait for fluent conditional operations.
use Illuminate\Support\Traits\Conditionable;

class MyBuilder
{
    use Conditionable;

    public function build()
    {
        return $this
            ->when($this->hasFeature(), fn($builder) => $builder->addFeature())
            ->unless($this->isDisabled(), fn($builder) => $builder->enable())
            ->when($this->isAdmin(), fn($builder) => $builder->addAdminFeatures());
    }
}
Key Methods:
  • when($condition, $callback, $default = null) - Execute if condition is truthy
  • unless($condition, $callback, $default = null) - Execute if condition is falsy
Advanced Usage:
// Higher-order when proxy
$builder->when()
    ->hasFeature(fn($b) => $b->addFeature())
    ->isAdmin(fn($b) => $b->addAdminFeatures())
    ->end();

// With default callbacks
$builder->when($condition,
    fn($b) => $b->doSomething(),
    fn($b) => $b->doSomethingElse()
);

Data Transfer Objects

ActivityData & MediaData

Structured data objects for consistent data handling across the application.
use Inly\Core\Data\ActivityData;
use Inly\Core\Data\MediaData;

// Activity data with properties
$activity = new ActivityData(
    description: 'User logged in',
    properties: new ActivityPropertiesData(['ip' => '192.168.1.1'])
);

// Media data handling
$media = new MediaData(
    name: 'profile.jpg',
    size: 1024,
    mimeType: 'image/jpeg'
);

Export Functionality

DataTableExport

Built-in export capabilities for data tables.
use Inly\Core\Exports\DataTableExport;

// Export data with notifications
DataTableExport::make($query)
    ->withNotification($user)
    ->export();

These features are designed to make development faster and more consistent across the application. Each can be used independently or combined for more complex functionality.