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

66 lines
1.4 KiB
PHP
Raw Normal View History

2019-04-15 02:10:54 +02:00
<?php
2019-05-11 05:32:07 +02:00
/**
* Invoice Ninja (https://invoiceninja.com)
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2019. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
2019-04-15 02:10:54 +02:00
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-16 00:26:21 +02:00
//$this->sanitize();
2019-05-09 07:29:31 +02:00
2019-04-28 14:23:22 +02:00
return [
2019-05-09 07:29:31 +02:00
'client_id' => 'required',
2019-05-16 00:26:21 +02:00
// 'documents' => 'mimes:png,ai,svg,jpeg,tiff,pdf,gif,psd,txt,doc,xls,ppt,xlsx,docx,pptx',
2019-04-28 14:23:22 +02:00
];
}
2019-05-16 00:26:21 +02:00
/* If we have an email address instead of a client_id - harvest the client_id here
2019-05-09 07:29:31 +02:00
public function sanitize()
{
$input = $this->all();
2019-05-16 00:26:21 +02:00
2019-05-09 07:29:31 +02:00
if(isset($input['email']) && !$input['client_id'])
2019-04-16 07:28:30 +02:00
{
2019-05-10 08:08:33 +02:00
$contact = ClientContact::company(auth()->user()->company()->id)->whereEmail($input['email'])->first();
2019-05-09 07:29:31 +02:00
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-05-16 00:26:21 +02:00
*/
2019-04-15 02:10:54 +02:00
2019-04-28 14:23:22 +02:00
}