<?php
 namespace App\Traits; use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Relations\MorphTo; trait LinksToCostOfSale { public function linkable(): MorphTo { return $this->morphTo(); } public function scopeLinkedTo(Builder $query, ?string $linkableType, $linkableId = null): Builder { if (! $linkableType) { return $query; } $query->where('linkable_type', $linkableType); if ($linkableId !== null && $linkableId !== '') { $query->where('linkable_id', $linkableId); } return $query; } } 