Installation
composer require milestone/elements
php artisan vendor:publish --provider="Milestone\Elements\ElementsServiceProvider" --tag="config"
php artisan migrate
Initial Setup
config/app.php under providers:
Milestone\Elements\ElementsServiceProvider::class,
config/elements.php file for required API keys, endpoints, or business logic configurations.First Use Case: Creating a Quotation
use Milestone\Elements\Facades\Elements;
$quotation = Elements::createQuotation([
'client_id' => 1,
'items' => [
['product_id' => 1, 'quantity' => 2, 'price' => 10.99],
['product_id' => 2, 'quantity' => 1, 'price' => 25.50],
],
]);
$quotation->save();
Quotation Management
Elements::createQuotation() with an array of items.$quotation = Elements::getQuotation($id);
$quotation->updateItems([...]);
$quotation->send();
Product Integration
$products = Elements::getProducts(['category' => 'electronics']);
$quotation->addProduct($productId, $quantity);
Business Logic Hooks
// Example: Apply a 10% discount if total exceeds $1000
Elements::quotationCreated(function ($quotation) {
if ($quotation->total > 1000) {
$quotation->applyDiscount(0.10);
}
});
API Integration
$response = Http::withHeaders([
'Authorization' => 'Bearer ' . config('elements.api_token'),
])->post('https://api.elements.example/quotes', $data);
Quotation, Product) align with your existing schema. Extend them if needed:
class CustomQuotation extends \Milestone\Elements\Models\Quotation {
protected $table = 'custom_quotes';
}
$this->app->bind(
\Milestone\Elements\Contracts\QuotationRepository::class,
\App\Repositories\CustomQuotationRepository::class
);
auth, role):
Route::middleware(['auth', 'can:manage.quotes'])->group(function () {
Route::resource('quotes', \Milestone\Elements\Http\Controllers\QuotationController::class);
});
Deprecated Methods
// Old way (if exists)
Elements::makeQuotation();
// New way (hypothetical)
Elements::createQuotation();
Missing Configuration
config/elements.php is properly set up with API keys, endpoints, or database connections. Example:
'api' => [
'base_url' => env('ELEMENTS_API_URL', 'https://api.elements.example'),
'token' => env('ELEMENTS_API_TOKEN'),
],
Database Migrations
php artisan migrate
--force (caution advised).Event System
QuotationCreated). Listen for them in EventServiceProvider:
protected $listen = [
\Milestone\Elements\Events\QuotationCreated::class => [
\App\Listeners\ApplyDiscount::class,
],
];
try-catch block to log errors:
try {
$response = Http::post(...);
} catch (\Throwable $e) {
\Log::error('Elements API Error: ' . $e->getMessage());
}
dd() to inspect objects:
$quotation = Elements::getQuotation(1);
dd($quotation->toArray());
Quotation model to add custom attributes:
class Quotation extends \Milestone\Elements\Models\Quotation {
protected $casts = [
'custom_field' => 'string',
];
}
$this->app->singleton(\Illuminate\Http\Client\PendingRequest::class, function () {
return Http::baseUrl(config('elements.test_api_url'));
});
php artisan vendor:publish --tag="elements-views"
// resources/views/vendor/elements/emails/quotation.blade.php
How can I help you explore Laravel packages today?