3
0
mirror of https://github.com/snipe/snipe-it.git synced 2026-08-18 11:15:42 +00:00
Files
snipe-it/app/Models/Traits/HasUploads.php

35 lines
1.3 KiB
PHP

<?php
namespace App\Models\Traits;
use App\Enums\ActionType;
use App\Models\Actionlog;
use App\Models\CompanyableScope;
trait HasUploads
{
public function uploads()
{
// Bypass FMCS company scoping: access is already gated by the policy on the
// parent object. Objects like AssetModel and Company have no company_id, so
// their upload logs always have company_id = null, which the scope would hide.
//
// Also surface QuantityAdjust rows that carry a receipt/invoice attachment
// (AdjustsQuantity trait writes the filename onto the same log row rather
// than emitting a separate 'uploaded' entry) so the Files tab shows those
// documents alongside regular uploads.
return $this->hasMany(Actionlog::class, 'item_id')
->withoutGlobalScope(CompanyableScope::class)
->where('item_type', self::class)
->whereIn('action_type', ['uploaded', ActionType::QuantityAdjust->value])
->whereNotNull('filename')
->whereNotIn('filename', function ($query) {
$query->select('filename')
->from('action_logs')
->where('item_type', '=', self::class)
->where('action_type', '=', 'upload deleted')
->where('item_id', $this->id);
});
}
}