invoiceninja/app/Http/Requests/Invoice/StoreInvoiceRequest.php

66 lines
1.4 KiB
PHP
Raw Normal View History

2019-04-15 10:10:54 +10:00
<?php
2019-05-11 13:32:07 +10: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 10:10:54 +10:00
namespace App\Http\Requests\Invoice;
use App\Http\Requests\Request;
2019-05-09 15:29:31 +10:00
use App\Models\ClientContact;
2019-04-15 10:10:54 +10: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 22:23:22 +10:00
public function rules()
{
2019-05-16 08:26:21 +10:00
//$this->sanitize();
2019-05-09 15:29:31 +10:00
2019-04-28 22:23:22 +10:00
return [
2019-05-09 15:29:31 +10:00
'client_id' => 'required',
2019-05-16 08:26:21 +10:00
// 'documents' => 'mimes:png,ai,svg,jpeg,tiff,pdf,gif,psd,txt,doc,xls,ppt,xlsx,docx,pptx',
2019-04-28 22:23:22 +10:00
];
}
2019-05-16 08:26:21 +10:00
/* If we have an email address instead of a client_id - harvest the client_id here
2019-05-09 15:29:31 +10:00
public function sanitize()
{
$input = $this->all();
2019-05-16 08:26:21 +10:00
2019-05-09 15:29:31 +10:00
if(isset($input['email']) && !$input['client_id'])
2019-04-16 15:28:30 +10:00
{
2019-05-10 16:08:33 +10:00
$contact = ClientContact::company(auth()->user()->company()->id)->whereEmail($input['email'])->first();
2019-05-09 15:29:31 +10:00
if($contact)
$input['client_id'] = $contact->client_id;
2019-04-16 15:28:30 +10:00
}
2019-05-09 15:29:31 +10:00
$this->replace($input);
}
2019-04-15 10:10:54 +10:00
public function messages()
{
}
2019-05-16 08:26:21 +10:00
*/
2019-04-15 10:10:54 +10:00
2019-04-28 22:23:22 +10:00
}