1. Go to this page and download the library: Download daikazu/laratone 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/ */
daikazu / laratone example snippets
return [
// Table prefix for Laratone tables
'table_prefix' => 'laratone_',
// Cache duration in seconds for color books and colors
'cache_time' => 3600,
// Reference white point for LAB color calculations
// Options: 'D50' (print), 'D55', 'D65' (daylight, default), 'D75'
'white_point' => 'D65',
// Default algorithm for finding closest colors: 'lab' or 'oklch'
'default_match_algorithm' => 'lab',
// Maximum number of colors that can be returned by find-closest
'max_match_limit' => 100,
];
// app/Providers/AppServiceProvider.php
use Illuminate\Routing\Router;
public function boot(Router $router): void
{
$router->aliasMiddleware('laratone', \App\Http\Middleware\YourCustomMiddleware::class);
}
// app/Http/Middleware/LaratoneApiMiddleware.php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Routing\Middleware\ThrottleRequests;
class LaratoneApiMiddleware extends ThrottleRequests
{
public function handle($request, Closure $next, $maxAttempts = 60, $decayMinutes = 1, $prefix = '')
{
// Add custom logic here (authentication, logging, etc.)
return parent::handle($request, $next, $maxAttempts, $decayMinutes, $prefix);
}
}
use Daikazu\Laratone\Facades\Laratone;
// Get all color books with colors
$colorBooks = Laratone::colorBooks();
// Get a specific color book by slug
$colorBook = Laratone::colorBookBySlug('color-book-plus-solid-coated');
// Create a new color book
$newColorBook = Laratone::createColorBook('My New Color Book');
// Create with custom slug
$newColorBook = Laratone::createColorBook('My Color Book', 'custom-slug');
// Add a single color to a color book (only hex => 'FF0000'],
['name' => 'Green', 'hex' => '00FF00'],
['name' => 'Blue', 'hex' => '0000FF'],
]);
// Get all colors from a color book
$colors = Laratone::getColorsFromBook($colorBook);
// Update a color
Laratone::updateColor($color, ['name' => 'Updated Color Name']);
// Delete a color
Laratone::deleteColor($color);
// Find closest matching colors to a target hex
$closest = Laratone::findClosestColors($colorBook, 'FF5500');
// Returns the single closest color by default
// Find multiple closest colors with specific algorithm
$closest = Laratone::findClosestColors(
colorBook: $colorBook,
targetHex: 'FF5500',
limit: 5,
algorithm: 'oklch' // or 'lab' (default)
);
// Each result
use Daikazu\Laratone\Models\Color;
$color = Color::first();
// Access color values as arrays
$color->hex; // 'FF0000' (b' => 67.22] (stored or calculated)
$color->cmyk; // ['c' => 0, 'm' => 100, 'y' => 100, 'k' => 0] (stored or calculated)
$color->oklch; // ['l' => 0.6279, 'c' => 0.2577, 'h' => 29.23] (stored or calculated)
// Access the parent color book
$colorBook = $color->colorBook;