|
@@ -61,16 +61,22 @@ class CreateOrUpdateRequest extends FormRequest
|
|
|
'assets' => [
|
|
|
'array',
|
|
|
function ($attribute, $value, $fail) {
|
|
|
- $count = Asset::query()
|
|
|
- ->leftJoin("project_asset", "assets.id", "=", "project_asset.asset_id")
|
|
|
- ->where("company_id", Auth::user()->company_id)
|
|
|
- ->whereNull("project_asset.id")
|
|
|
- ->whereIn('assets.id', $value)->count();
|
|
|
+ $assetIds = Asset::query()->whereIn('id', $value)->pluck('id')->toArray();
|
|
|
|
|
|
- if ($count != count($value)) {
|
|
|
+ if (count(array_diff($value, $assetIds)) > 0) {
|
|
|
$fail('The selected asset is invalid.');
|
|
|
}
|
|
|
}
|
|
|
+// $count = Asset::query()
|
|
|
+// ->leftJoin("project_asset", "assets.id", "=", "project_asset.asset_id")
|
|
|
+// ->where("company_id", Auth::user()->company_id)
|
|
|
+// ->whereNull("project_asset.id")
|
|
|
+// ->whereIn('assets.id', $value)->count();
|
|
|
+//
|
|
|
+// if ($count != count($value)) {
|
|
|
+// $fail('The selected asset is invalid.');
|
|
|
+// }
|
|
|
+
|
|
|
],
|
|
|
'latitude' => 'numeric',
|
|
|
'longitude' => 'numeric',
|