mirror of
				https://github.com/invoiceninja/invoiceninja.git
				synced 2025-10-28 03:13:26 -04:00 
			
		
		
		
	
		
			
				
	
	
		
			65 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			65 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
| <?php
 | |
| /**
 | |
|  * Invoice Ninja (https://invoiceninja.com).
 | |
|  *
 | |
|  * @link https://github.com/invoiceninja/invoiceninja source repository
 | |
|  *
 | |
|  * @copyright Copyright (c) 2023. Invoice Ninja LLC (https://invoiceninja.com)
 | |
|  *
 | |
|  * @license https://www.elastic.co/licensing/elastic-license
 | |
|  */
 | |
| 
 | |
| namespace App\Http\Requests\Invoice;
 | |
| 
 | |
| use App\Http\Requests\Request;
 | |
| use Illuminate\Http\UploadedFile;
 | |
| 
 | |
| class UploadInvoiceRequest extends Request
 | |
| {
 | |
|     /**
 | |
|      * Determine if the user is authorized to make this request.
 | |
|      *
 | |
|      * @return bool
 | |
|      */
 | |
|     public function authorize() : bool
 | |
|     {
 | |
|         /** @var \App\Models\User $user */
 | |
|         $user = auth()->user();
 | |
|         
 | |
|         return $user->can('edit', $this->invoice);
 | |
|     }
 | |
| 
 | |
|     public function rules()
 | |
|     {
 | |
|         $rules = [];
 | |
| 
 | |
|         if ($this->file('documents') && is_array($this->file('documents'))) {
 | |
|             $rules['documents.*'] = $this->file_validation;
 | |
|         } elseif ($this->file('documents')) {
 | |
|             $rules['documents'] = $this->file_validation;
 | |
|         }
 | |
| 
 | |
|         if ($this->file('file') && is_array($this->file('file'))) {
 | |
|             $rules['file.*'] = $this->file_validation;
 | |
|         } elseif ($this->file('file')) {
 | |
|             $rules['file'] = $this->file_validation;
 | |
|         }
 | |
| 
 | |
|         $rules['is_public'] = 'sometimes|boolean';
 | |
|         
 | |
|         return $rules;
 | |
|     }
 | |
| 
 | |
|     public function prepareForValidation()
 | |
|     {
 | |
|         $input = $this->all();
 | |
| 
 | |
|         if(isset($input['is_public'])) {
 | |
|             $input['is_public'] = $this->toBoolean($input['is_public']);
 | |
|         }
 | |
| 
 | |
|         $this->replace($input);
 | |
|       
 | |
|     }
 | |
| }
 |