tinkering with the polymorphic eager load
This commit is contained in:
@@ -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) {
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user