1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-14 07:02:34 +01:00
invoiceninja/app/Http/Requests/Invoice/UploadInvoiceRequest.php

71 lines
1.8 KiB
PHP
Raw Normal View History

2021-02-15 12:34:05 +01:00
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
2023-01-28 23:21:40 +01:00
* @copyright Copyright (c) 2023. Invoice Ninja LLC (https://invoiceninja.com)
2021-02-15 12:34:05 +01:00
*
2021-06-16 08:58:16 +02:00
* @license https://www.elastic.co/licensing/elastic-license
2021-02-15 12:34:05 +01:00
*/
namespace App\Http\Requests\Invoice;
use App\Http\Requests\Request;
2023-03-28 22:53:46 +02:00
use Illuminate\Http\UploadedFile;
2021-02-15 12:34:05 +01:00
class UploadInvoiceRequest extends Request
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize() : bool
{
return auth()->user()->can('edit', $this->invoice);
}
public function rules()
{
$rules = [];
2021-02-15 12:34:05 +01:00
2023-03-18 08:24:56 +01:00
if ($this->file('documents') && is_array($this->file('documents'))) {
2023-02-27 10:12:59 +01:00
$rules['documents.*'] = $this->file_validation;
2023-03-18 08:24:56 +01:00
} elseif ($this->file('documents')) {
2023-02-27 10:12:59 +01:00
$rules['documents'] = $this->file_validation;
2023-03-18 08:24:56 +01:00
}
2021-02-15 12:34:05 +01:00
2023-02-27 10:12:59 +01:00
if ($this->file('file') && is_array($this->file('file'))) {
$rules['file.*'] = $this->file_validation;
} elseif ($this->file('file')) {
$rules['file'] = $this->file_validation;
}
2022-03-09 10:39:32 +01:00
return $rules;
2021-02-15 12:34:05 +01:00
}
2023-02-27 10:12:59 +01:00
public function prepareForValidation()
{
2023-03-28 22:53:46 +02:00
//tests to see if upload via binary data works.
// if(request()->getContent())
// {
// // $file = new UploadedFile(request()->getContent(), request()->header('filename'));
// $file = new UploadedFile(request()->getContent(), 'something.png');
// // request()->files->set('documents', $file);
// $this->files->add(['file' => $file]);
// // Merge it in request also (As I found this is not needed in every case)
// $this->merge(['file' => $file]);
// }
2023-02-27 10:12:59 +01:00
}
2021-02-15 12:34:05 +01:00
}