. */ declare(strict_types=1); namespace FireflyIII\Api\V1\Requests; use FireflyIII\Models\Bill; use FireflyIII\Models\ImportJob; use FireflyIII\Models\TransactionJournal; use FireflyIII\Rules\IsValidAttachmentModel; /** * Class AttachmentStoreRequest * @codeCoverageIgnore */ class AttachmentStoreRequest extends Request { /** * Authorize logged in users. * * @return bool */ public function authorize(): bool { // Only allow authenticated users return auth()->check(); } /** * Get all data from the request. * * @return array */ public function getAll(): array { return [ 'filename' => $this->string('filename'), 'title' => $this->string('title'), 'notes' => $this->string('notes'), 'model' => $this->string('model'), 'model_id' => $this->integer('model_id'), ]; } /** * The rules that the incoming request must be matched against. * * @return array */ public function rules(): array { $models = implode( ',', [ str_replace('FireflyIII\\Models\\', '', Bill::class), str_replace('FireflyIII\\Models\\', '', ImportJob::class), str_replace('FireflyIII\\Models\\', '', TransactionJournal::class), ] ); $model = $this->string('model'); return [ 'filename' => 'required|between:1,255', 'title' => 'between:1,255', 'notes' => 'between:1,65000', 'model' => sprintf('required|in:%s', $models), 'model_id' => ['required', 'numeric', new IsValidAttachmentModel($model)], ]; } }