2016-05-01 13:31:10 +02:00
|
|
|
<?php namespace App\Http\Requests;
|
2016-01-06 21:46:11 +01:00
|
|
|
|
|
|
|
use Auth;
|
|
|
|
use App\Http\Requests\Request;
|
|
|
|
use Illuminate\Validation\Factory;
|
|
|
|
use App\Models\Invoice;
|
|
|
|
|
|
|
|
class UpdateInvoiceRequest extends Request
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Determine if the user is authorized to make this request.
|
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function authorize()
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the validation rules that apply to the request.
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function rules()
|
|
|
|
{
|
|
|
|
if ($this->action == ACTION_ARCHIVE) {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
|
|
|
|
$publicId = $this->route('invoices');
|
|
|
|
$invoiceId = Invoice::getPrivateId($publicId);
|
|
|
|
|
|
|
|
$rules = [
|
2016-02-09 22:51:08 +01:00
|
|
|
'invoice_items' => 'valid_invoice_items',
|
2016-01-06 21:46:11 +01:00
|
|
|
'invoice_number' => 'unique:invoices,invoice_number,'.$invoiceId.',id,account_id,'.Auth::user()->account_id,
|
|
|
|
'discount' => 'positive',
|
|
|
|
];
|
|
|
|
|
|
|
|
return $rules;
|
|
|
|
}
|
|
|
|
}
|