tinkering with the polymorphic eager load

This commit is contained in:
Godfrey M
2025-01-07 09:08:36 -08:00
parent 0ec25d55a0
commit e12c7473f8
4 changed files with 34 additions and 5 deletions
+5 -4
View File
@@ -1117,7 +1117,8 @@ class ReportsController extends Controller
if ($showDeleted) {
$query->withTrashed()->with(['assignedTo']);
} else {
}
else {
$query->with(['assignedTo' => function ($query) {
$query->withTrashed();
}]);
@@ -1129,10 +1130,10 @@ class ReportsController extends Controller
$filtered = $chunk->filter(function ($acceptance) {
$acceptance_checkoutable_flag = false;
if($acceptance->checkoutable) {
$acceptance_checkoutable_flag = $acceptance->assignedTo;
if ($acceptance->checkoutable){
$acceptance_checkoutable_flag = $acceptance->checkoutable->assignedTo();
}
// Return true if criteria match
// Return true if user
return $acceptance->checkoutable_type === 'App\Models\Asset' && $acceptance_checkoutable_flag;
})->map(function ($acceptance) {
+24
View File
@@ -0,0 +1,24 @@
<?php
namespace App\Http\Traits;
trait CheckoutableTrait
{
public const LOCATION = 'location';
public const ASSET = 'asset';
public const USER = 'user';
public function checkedOutToUser(): bool
{
return $this->assignedType() === self::USER;
}
public function checkedOutToLocation(): bool
{
return $this->assignedType() === self::LOCATION;
}
public function checkedOutToAsset(): bool
{
return $this->assignedType() === self::ASSET;
}
}