1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-11 05:32:39 +01:00
invoiceninja/app/Http/Requests/Invoice/StoreInvoiceRequest.php
2019-05-09 15:29:31 +10:00

57 lines
1.1 KiB
PHP

<?php
namespace App\Http\Requests\Invoice;
use App\Http\Requests\Request;
use App\Models\ClientContact;
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);
}
public function rules()
{
$this->sanitize();
return [
'client_id' => 'required',
'documents' => 'mimes:png,ai,svg,jpeg,tiff,pdf,gif,psd,txt,doc,xls,ppt,xlsx,docx,pptx',
];
}
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'])
{
$contact = ClientContact::company()->whereEmail($input['email'])->first();
if($contact)
$input['client_id'] = $contact->client_id;
}
$this->replace($input);
}
public function messages()
{
}
}