1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-09-21 08:51:34 +02:00
invoiceninja/app/Http/Requests/Invoice/StoreInvoiceRequest.php

57 lines
1.1 KiB
PHP
Raw Normal View History

2019-04-15 02:10:54 +02:00
<?php
namespace App\Http\Requests\Invoice;
use App\Http\Requests\Request;
2019-05-09 07:29:31 +02:00
use App\Models\ClientContact;
2019-04-15 02:10:54 +02:00
use App\Models\Invoice;
class StoreInvoiceRequest extends Request
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize() : bool
{
return auth()->user()->can('create', Invoice::class);
}
2019-04-28 14:23:22 +02:00
public function rules()
{
2019-05-09 07:29:31 +02:00
$this->sanitize();
2019-04-28 14:23:22 +02:00
return [
2019-05-09 07:29:31 +02:00
'client_id' => 'required',
2019-04-28 14:23:22 +02:00
'documents' => 'mimes:png,ai,svg,jpeg,tiff,pdf,gif,psd,txt,doc,xls,ppt,xlsx,docx,pptx',
];
}
2019-04-15 02:10:54 +02:00
2019-05-09 07:29:31 +02:00
public function sanitize()
{
$input = $this->all();
/** If we have an email address instead of a client_id - harvest the client_id here */
if(isset($input['email']) && !$input['client_id'])
2019-04-16 07:28:30 +02:00
{
2019-05-09 07:29:31 +02:00
$contact = ClientContact::company()->whereEmail($input['email'])->first();
if($contact)
$input['client_id'] = $contact->client_id;
2019-04-16 07:28:30 +02:00
}
2019-05-09 07:29:31 +02:00
$this->replace($input);
}
2019-04-15 02:10:54 +02:00
public function messages()
{
}
2019-04-28 14:23:22 +02:00
}