Skip to main content

Overview

The Company model represents a business entity in ElectroFix. Each company has its own users, customers, equipment, orders, inventory, and billing documents. This is the top-level organizational model in the system.

Properties

Fillable Attributes

name
string
required
The company’s business name
owner_name
string
Full name of the company owner
owner_email
string
Email address of the company owner
owner_phone
string
Phone number of the company owner
tax_id
string
Tax identification number for the company
billing_email
string
Email address for billing communications
billing_phone
string
Phone number for billing inquiries
address_line
string
Street address of the company
city
string
City where the company is located
state
string
State or province of the company
country
string
Country where the company operates
postal_code
string
Postal or ZIP code
currency
string
Currency code used by the company (e.g., USD, EUR)
vat_percentage
decimal
Default VAT/tax percentage for billing (stored with 2 decimal precision)
notes
text
Additional notes or information about the company

Casts

protected function casts(): array
{
    return [
        'vat_percentage' => 'decimal:2',
    ];
}
The vat_percentage field is automatically cast to a decimal with 2 decimal places.

Relationships

users()

Type: HasMany Returns all users belonging to this company.
public function users(): HasMany
{
    return $this->hasMany(User::class);
}

subscription()

Type: HasOne Returns the active subscription for this company.
public function subscription(): HasOne
{
    return $this->hasOne(Subscription::class);
}

customers()

Type: HasMany Returns all customers belonging to this company.
public function customers(): HasMany
{
    return $this->hasMany(Customer::class);
}

equipments()

Type: HasMany Returns all equipment registered to this company.
public function equipments(): HasMany
{
    return $this->hasMany(Equipment::class);
}

orders()

Type: HasMany Returns all repair orders for this company.
public function orders(): HasMany
{
    return $this->hasMany(Order::class);
}

inventoryItems()

Type: HasMany Returns all inventory items managed by this company.
public function inventoryItems(): HasMany
{
    return $this->hasMany(InventoryItem::class);
}

inventoryMovements()

Type: HasMany Returns all inventory movements tracked for this company.
public function inventoryMovements(): HasMany
{
    return $this->hasMany(InventoryMovement::class);
}

billingDocuments()

Type: HasMany Returns all billing documents (invoices, quotes, etc.) for this company.
public function billingDocuments(): HasMany
{
    return $this->hasMany(BillingDocument::class);
}

aiUsages()

Type: HasMany Returns all AI usage records for this company.
public function aiUsages(): HasMany
{
    return $this->hasMany(CompanyAiUsage::class);
}

Usage Examples

Creating a New Company

$company = Company::create([
    'name' => 'Tech Repairs Inc.',
    'owner_name' => 'John Doe',
    'owner_email' => 'john@techrepairs.com',
    'owner_phone' => '+1234567890',
    'tax_id' => '12-3456789',
    'address_line' => '123 Main Street',
    'city' => 'San Francisco',
    'state' => 'CA',
    'country' => 'USA',
    'postal_code' => '94102',
    'currency' => 'USD',
    'vat_percentage' => 8.50,
]);

Accessing Company Relationships

// Get all users for a company
$users = $company->users;

// Get company subscription
$subscription = $company->subscription;

// Get all customers
$customers = $company->customers;

// Get all orders with equipment details
$orders = $company->orders()->with('equipment')->get();

Updating Company Information

$company->update([
    'vat_percentage' => 9.00,
    'billing_email' => 'billing@techrepairs.com',
]);

Source Reference

Model file: /home/daytona/workspace/source/app/Models/Company.php

Build docs developers (and LLMs) love