v5.0.0 update

This commit is contained in:
Mohit Panjwani
2021-11-30 18:58:19 +05:30
parent d332712c22
commit 082d5cacf2
1253 changed files with 88309 additions and 71741 deletions

View File

@ -2,7 +2,10 @@
namespace Crater\Http\Requests;
use Crater\Models\Address;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Support\Arr;
use Illuminate\Support\Facades\Auth;
use Illuminate\Validation\Rule;
class CustomerRequest extends FormRequest
@ -28,29 +31,151 @@ class CustomerRequest extends FormRequest
'name' => [
'required',
],
'addresses.*.address_street_1' => [
'max:255',
],
'addresses.*.address_street_2' => [
'max:255',
],
'email' => [
'email',
'nullable',
'unique:users,email',
Rule::unique('customers')->where('company_id', $this->header('company'))
],
'password' => [
'nullable',
],
'phone' => [
'nullable',
],
'company_name' => [
'nullable',
],
'contact_name' => [
'nullable',
],
'website' => [
'nullable',
],
'prefix' => [
'nullable',
],
'enable_portal' => [
'nullable',
],
'currency_id' => [
'nullable',
],
'billing.name' => [
'nullable',
],
'billing.address_street_1' => [
'nullable',
],
'billing.address_street_2' => [
'nullable',
],
'billing.city' => [
'nullable',
],
'billing.state' => [
'nullable',
],
'billing.country_id' => [
'nullable',
],
'billing.zip' => [
'nullable',
],
'billing.phone' => [
'nullable',
],
'billing.fax' => [
'nullable',
],
'shipping.name' => [
'nullable',
],
'shipping.address_street_1' => [
'nullable',
],
'shipping.address_street_2' => [
'nullable',
],
'shipping.city' => [
'nullable',
],
'shipping.state' => [
'nullable',
],
'shipping.country_id' => [
'nullable',
],
'shipping.zip' => [
'nullable',
],
'shipping.phone' => [
'nullable',
],
'shipping.fax' => [
'nullable',
]
];
if ($this->isMethod('PUT') && $this->email != null) {
$rules = [
'email' => [
'email',
'nullable',
Rule::unique('users')->ignore($this->route('customer')->id),
],
$rules['email'] = [
'email',
'nullable',
Rule::unique('customers')->ignore($this->route('customer')->id),
];
};
return $rules;
}
public function getCustomerPayload()
{
return collect($this->validated())
->only([
'name',
'email',
'currency_id',
'password',
'phone',
'prefix',
'company_name',
'contact_name',
'website',
'enable_portal',
'estimate_prefix',
'payment_prefix',
'invoice_prefix',
])
->merge([
'creator_id' => $this->user()->id,
'company_id' => $this->header('company'),
])
->toArray();
}
public function getShippingAddress()
{
return collect($this->shipping)
->merge([
'type' => Address::SHIPPING_TYPE
])
->toArray();
}
public function getBillingAddress()
{
return collect($this->billing)
->merge([
'type' => Address::BILLING_TYPE
])
->toArray();
}
public function hasAddress(array $address)
{
$data = Arr::where($address, function ($value, $key) {
return isset($value);
});
return $data;
}
}