['required', 'string', 'between:1,60', Rule::unique('locations', 'short')->ignore($location)], 'long' => ['string', 'nullable', 'between:1,191'], ]; } /** * Validates location input and returns the model attributes it describes. * * @param ActionInput $input * @return array{short: string, long: string|null} */ public static function attributes(array $input, ?Location $location = null): array { $input = Validator::make($input, self::rules($location))->safe(); return [ 'short' => $input->string('short')->toString(), 'long' => $input->filled('long') ? $input->string('long')->toString() : null, ]; } /** * @param ActionInput $input */ public function create(array $input): Location { $attributes = self::attributes($input); $extensions = ValidatedExtensionValues::of($input['extensions'] ?? null); return DB::transaction(function () use ($attributes, $extensions): Location { $location = Location::query()->create($attributes); $this->extensions->save($location, $extensions); return $location; }); } }