|string> */ public function rules(): array { return [ 'name' => 'required|max:150', 'code' => [ 'required', 'max:50', ], 'const' => 'numeric', 'begin' => 'required|date', 'end' => 'required|date', 'type' => 'required|max:20', 'acl' => 'required|in:private,custom', 'available_days' => 'numeric', 'whitelist' => [ 'array', function ($attribute, $value, $fail) { $userCount = User::where("company_id", Auth::user()->company_id)->whereIn('id', $value)->count(); if ($userCount != count($value)) { $fail('The selected user is invalid.'); } } ], 'plans' => [ 'array', function ($attribute, $value, $fail) { $count = Plan::where("company_id", Auth::user()->company_id)->whereIn('id', $value)->count(); if ($count != count($value)) { $fail('The selected plan is invalid.'); } } ], '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(); if ($count != count($value)) { $fail('The selected asset is invalid.'); } } ], 'latitude' => 'numeric', 'longitude' => 'numeric', ]; } }