Skip to content

Using Queries ​

Start database-touching Eloquent queries with Model::query().

Do not pass a column array to get() by default. Prefer loading the complete model when the result is not large. Select specific columns only when the data size justifies that optimization.

Add a collection PHPDoc to every query ending in get() so IDEs and PHPStan can resolve the model type correctly.

php
use Illuminate\Database\Eloquent\Collection;

/** @var Collection<int, WorkOrder> $workOrders */
$workOrders = WorkOrder::query()
    ->whereIn('manufacture_order_id', $manufactureOrderIds)
    ->whereIn('status', [
        WorkOrderStatus::PLANNED->value,
        WorkOrderStatus::IN_PROGRESS->value,
    ])
    ->get();

Internal engineering documentation