29 lines
671 B
PHP
29 lines
671 B
PHP
<?php
|
|
|
|
namespace Modules\IndustrialEngineering\Support;
|
|
|
|
use App\Business;
|
|
use App\User;
|
|
|
|
class ActorResolver
|
|
{
|
|
public static function id(?int $businessId = null): ?int
|
|
{
|
|
$userId = auth()->id();
|
|
if ($userId && User::where('id', $userId)->exists()) {
|
|
return (int) $userId;
|
|
}
|
|
|
|
if ($businessId) {
|
|
$ownerId = Business::where('id', $businessId)->value('owner_id');
|
|
if ($ownerId && User::where('id', $ownerId)->exists()) {
|
|
return (int) $ownerId;
|
|
}
|
|
}
|
|
|
|
$fallback = User::orderBy('id')->value('id');
|
|
|
|
return $fallback ? (int) $fallback : null;
|
|
}
|
|
}
|