60 lines
		
	
	
		
			1.8 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			60 lines
		
	
	
		
			1.8 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
| <?php
 | |
| 
 | |
| namespace App\Http\Requests\Banking;
 | |
| 
 | |
| use App\Abstracts\Http\FormRequest;
 | |
| use App\Utilities\Date;
 | |
| 
 | |
| class Transaction extends FormRequest
 | |
| {
 | |
|     /**
 | |
|      * Get the validation rules that apply to the request.
 | |
|      *
 | |
|      * @return array
 | |
|      */
 | |
|     public function rules()
 | |
|     {
 | |
|         $attachment = 'nullable';
 | |
| 
 | |
|         if ($this->files->get('attachment')) {
 | |
|             $attachment = 'mimes:' . config('filesystems.mimes') . '|between:0,' . config('filesystems.max_size') * 1024;
 | |
|         }
 | |
| 
 | |
|         // Check if store or update
 | |
|         if ($this->getMethod() == 'PATCH') {
 | |
|             $id = $this->transaction->getAttribute('id');
 | |
|         } else {
 | |
|             $id = null;
 | |
|         }
 | |
| 
 | |
|         // Get company id
 | |
|         $company_id = (int) $this->request->get('company_id');
 | |
| 
 | |
|         return [
 | |
|             'type' => 'required|string',
 | |
|             'number' => 'required|string|unique:transactions,NULL,' . $id . ',id,company_id,' . $company_id . ',deleted_at,NULL',
 | |
|             'account_id' => 'required|integer',
 | |
|             'paid_at' => 'required|date_format:Y-m-d H:i:s',
 | |
|             'amount' => 'required|amount',
 | |
|             'currency_code' => 'required|string|currency',
 | |
|             'currency_rate' => 'required|gt:0',
 | |
|             'document_id' => 'nullable|integer',
 | |
|             'contact_id' => 'nullable|integer',
 | |
|             'category_id' => 'required|integer',
 | |
|             'payment_method' => 'required|string',
 | |
|             'attachment.*' => $attachment,
 | |
|             'recurring_count' => 'gte:0',
 | |
|             'recurring_interval' => 'exclude_unless:recurring_frequency,custom|gt:0',
 | |
|         ];
 | |
|     }
 | |
| 
 | |
|     public function withValidator($validator)
 | |
|     {
 | |
|         if ($validator->errors()->count()) {
 | |
|             $paid_at = Date::parse($this->request->get('paid_at'))->format('Y-m-d');
 | |
| 
 | |
|             $this->request->set('paid_at', $paid_at);
 | |
|         }
 | |
|     }
 | |
| }
 |