File "StoreAddressBookRequest.php"
Full Path: /home/clickysoft/public_html/jmapi5.clickysoft.net/app/Http/Requests/Admin/StoreAddressBookRequest.php
File size: 2.24 KB
MIME-type: text/x-php
Charset: utf-8
<?php
namespace App\Http\Requests\Admin;
use Gate;
use Illuminate\Foundation\Http\FormRequest;
class StoreAddressBookRequest extends FormRequest
{
public function authorize()
{
return (auth()->user()->user_type == 3 || Gate::allows('address_book_create'));
}
public function rules()
{
return [
'user_id' => [
auth()->user()->user_type == 1 ? 'required' : 'nullable',
'exists:users,id',
],
'company_name' => [
'nullable',
'string',
'max:50',
],
'primary_contact_name' => [
'required',
'string',
'max:50',
],
'primary_contact_email' => [
'required',
'email',
],
'secondary_contact_name' => [
'nullable',
'string',
'max:50',
],
'secondary_contact_email' => [
'nullable',
'email',
],
'address_line_1' => [
'required',
'string',
],
'address_line_2' => [
'nullable',
'string',
],
'city' => [
'required',
'string',
'max:50',
],
'state_id' => [
'required',
'integer',
'exists:state_sales_taxes,id',
],
'zipcode' => [
'required',
'integer',
'max_digits:10',
],
'phone_number' => [
'nullable',
'regex:/^[0-9]+$/',
'max_digits:20',
],
'is_default' => [
'required',
'in:0,1',
],
];
}
public function messages()
{
return [
'zipcode.max_digits' => 'Zipcode can not contain more than 10 digits.',
'phone_number.max_digits' => 'Phone number can not contain more than 20 digits.',
'phone_number.regex' => 'Phone number can only contain numbers.',
];
}
}