Request
Overview
The CustomerRequest class is designed to handle various customer-related actions within the system. It serves as the base class for managing requests related to customer information, including creation, updates, and deletions. This class acts as a central point of reference for customer operations, enabling the execution of specific tasks such as creating customer addresses, handling customer issues, and managing customer attributes. By organizing these tasks into a coherent structure, the CustomerRequest class streamlines the process of managing customer data and ensures that all related actions are handled consistently.
Request Structure
- Namespace: Toolstation\Customers\Http\Requests
- Extends:
CustomerRequest&BaseRequest - Uses: Illuminate\Support\Carbon, Toolstation\Core\Http\Requests\BaseRequest
Customer Module Request
The customer module fires the following request.
| Request Name | Description |
|---|---|
Toolstation\Customers\Requests\CreateCustomerAddressRequest | Validates and formats the data for creating a customer address. |
Toolstation\Customers\Requests\CreateCustomerAttributeRequest | Validates and formats the data for creating a customer attribute. |
Toolstation\Customers\Requests\CreateCustomerIssueRequest | Validates and formats the data for creating a customer issue. |
Toolstation\Customers\Requests\CreateCustomerNoteRequest | Validates and formats the data for creating a customer note. |
Toolstation\Customers\Requests\CreateCustomerRequest | Validates and formats the data for creating a new customer. |
Toolstation\Customers\Requests\CustomerCatalogueRequest | Validates and formats the data for a customer catalogue request. |
Toolstation\Customers\Requests\CustomerContactUsRequest | Validates and formats the data for a customer contact request. |
Toolstation\Customers\Requests\CustomerRequest | Formats and retrieves the data from the customer request. |
Toolstation\Customers\Requests\CustomerSignatureRequest | Validates the data for a customer signature request. |
Toolstation\Customers\Requests\DeleteCustomerAttributeRequest | Checks if the user is authorized to delete a customer attribute. |
Toolstation\Customers\Requests\PatchCustomerAddressRequest | Validates and formats address update requests for a customer. |
Toolstation\Customers\Requests\UpdateCustomerAddressRequest | Validates and formats required data for updating a customer`s address. |
Toolstation\Customers\Requests\UpdateCustomerIssueNotRequest | Validates and formats the urgency flag for updating a customer issue note. |
Toolstation\Customers\Requests\UpdateCustomerIssueRequest | Validates and formats data for updating a customer`s issue, including resolution details if marked as completed. |
Toolstation\Customers\Requests\UpdateCustomerNoteRequest | Validates and formats the urgency flag for updating a customer note. |
Toolstation\Customers\Requests\UpdateCustomerRequest | Validates and formats customer data updates, including handling nested contact preferences and optional VAT number. |
CreateCustomerAddressRequest Overview
The CreateCustomerAddressRequest class is used to handle the request for creating a customers address. It extends the CustomerRequest class and provides methods for authorization, validation rules, and formatting request data.
Request Structure
- Authorization Method: Checks if the user is authenticated to make the request.
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return $this->user(); // There must be an authenticated user.
}
- Validation Rules Method: Defines rules for the request data:
type: Required; must be one of 1, 2, or 3.house: Required; string with a maximum of 64 characters.a_road: Optional; string with a maximum of 32 characters.b_road: Optional; string with a maximum of 32 characters.postcode: Required; string with a maximum of 16 characters.town: Required; string with a maximum of 32 characters.county: Optional; string with a maximum of 32 characters.country: Required; must exist in main.data_countries table under dco_uid column.
/**
* Returns a formatted array containing the requests form data.
*
* @return array
*/
public function getRequestData()
{
return [
'user' => $this->getUserStringFromRequest(),
'date' => Carbon::now(),
'type' => $this->get('type'),
'house' => $this->get('house'),
'aRoad' => $this->get('a_road', ''),
'bRoad' => $this->get('b_road', ''),
'postcode' => $this->get('postcode'),
'town' => $this->get('town'),
'county' => $this->get('county', ''),
'country' => $this->get('country'),
];
}
CreateCustomerAttributeRequest Overview
The CreateCustomerAttributeRequest class is a part of the Toolstation\Customers\Http\Requests namespace. It extends from CustomerRequest, suggesting it inherits general request handling functionality from this base class. This class is designed to handle requests related to creating or updating customer attributes. It includes validation logic to ensure that only valid data is processed and provides methods to format and return the data in a specific structure.
Request Structure
- Constant Definition:
ATTRIBUTE_WHITELISTis a constant array that defines a whitelist of valid customer attributes. Each attribute is mapped to a unique status code:Age Checkedis mapped to 1.Declined Telephoneis mapped to 6, and so on.
public const ATTRIBUTE_WHITELIST = [
'Age Checked' => X,
'Declined Telephone' => X,
'Declined Mobile' => X,
'Declined Email' => X,
'Customer Card No.' => X,
'Account Type' => X,
];
- Default Rules: The rules method defines validation rules for the request data:
The key must be one of the keys in the ATTRIBUTE_WHITELIST. This is enforced using Rule::in(array_keys(self::ATTRIBUTE_WHITELIST)).The value field is required.
- Special Case for Customer Card No:
If the key corresponds to 'Customer Card No.', the validation rules are modified. Specifically, the value must be unique across all users in the user_customer_notes table. This uniqueness constraint is enforced using the unique rule:
public function rules()
{
$rules = [
'key' => ['required', Rule::in(array_keys(self::ATTRIBUTE_WHITELIST))],
'value' => 'required',
];
// Value of the Customer Card attribute must be unique across all users
if (isset(self::ATTRIBUTE_WHITELIST[$this->get('key')]) &&
self::ATTRIBUTE_WHITELIST[$this->get('key')]
=== _tsc('customers.attributes.{TS_REGION}.customer_card_number')
) {
$rules = [
'key' => ['required', Rule::in(array_keys(self::ATTRIBUTE_WHITELIST))],
'value' => 'required|unique:main.user_customer_notes,ucn_val,NULL,ucn_uid,ucn_sst_uid,10',
];
}
return $rules;
}
CreateCustomerIssueRequest Overview
The CreateCustomerIssueRequest class is a custom request class in Laravel that handles the validation and processing of customer issue requests. It extends the CustomerRequest class and is used to validate and prepare data for creating a new customer issue. The class uses various services and rules to validate the request data and ensure that it conforms to the required format. The class also provides a method for retrieving the request data in a formatted array.
Request Structure
- Authorization Method: Checks if the user is authenticated to make the request.
- Validation Rules: The rules method defines validation rules for the request data:
The title field is required.The description field is required.
- Request Data Formatting: The getRequestData method returns an array containing the formatted request data. The array contains the following keys:
title: The title of the customer issue.description: The description of the customer issue.
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'title' => 'required',
'description' => 'required',
];
}
/**
* Get the request data in a formatted array.
*
* @return array
*/
public function getRequestData()
{
return [
'title' => $this->get('title'),
'description' => $this->get('description'),
];
}
CreateCustomerNoteRequest Overview
The CreateCustomerNoteRequest class is a custom request class that handles the validation and processing of customer note requests. It extends the CustomerRequest class and is used to validate and prepare data for creating a new customer note. The class uses various services and rules to validate the request data and ensure that it conforms to the required format. The class also provides a method for retrieving the request data in a formatted array.
Request Structure
- Authorization Method: Checks if the user is authenticated to make the request.
- Validation Rules: The rules method defines validation rules for the request data:
The text field is required.The urgency field is required.
- Request Data Formatting: The getRequestData method returns an array containing the formatted request data. The array contains the following keys:
text: The text of the customer note.urgency: The urgency of the customer note.user=> $this->getUserStringFromRequest().date=> Carbon::now().
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'text' => 'required',
'urgency' => 'required',
];
}
/**
* Get the request data in a formatted array.
*
* @return array
*/
public function getRequestData()
{
return [
'text' => $this->get('text'),
'urgency' => $this->get('urgency'),
'user' => $this->getUserStringFromRequest(),
'date' => Carbon::now(),
];
}
CreateCustomerRequest Overview
The CreateCustomerRequest class is a custom request class that handles the validation and processing of customer creation requests. It extends the CustomerRequest class and is used to validate and prepare data for creating a new customer. The class uses various services and rules to validate the request data and ensure that it confirms to the required format. The class also provides a method for retrieving the request data in a formatted array.
Request Structure
- Authorization Method: Checks if the user is authenticated to make the request.
- Constant Definition:
ATTRIBUTE_WHITELISTis a constant array that defines a whitelist of valid customer attributes. Each attribute is mapped to a unique status code:Age Checkedis mapped to 1.Declined Telephoneis mapped to 6, and so on.
public const ATTRIBUTE_WHITELIST = [
'Age Checked' => X,
'Declined Telephone' => X,
'Declined Mobile' => X,
'Declined Email' => X,
'Customer Card No.' => X,
'Account Type' => X,
];
- Validation Rules: The rules method defines validation rules for the request data.
- Request Data Formatting: The getRequestData method returns an array containing the formatted request data. The array contains the following keys.
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'username' => 'email|unique:main.user_customers,ucu_username|string|max:64',
'title' => 'required|string|max:32',
'first_name' => 'required|string|max:32',
'last_name' => 'required|string|max:32',
'telephone' => 'string|max:32',
'mobile' => 'string|max:32',
'email' => 'email|max:254',
'company' => 'string|max:32',
'job_title' => 'string|max:32',
'vat_number' => 'string|max:100',
'contact_preferences' => 'array',
'contact_preferences.mail_catalogues' => 'boolean',
'contact_preferences.order_query' => 'array',
'contact_preferences.order_query.email' => 'boolean',
'contact_preferences.order_query.telephone' => 'boolean',
'contact_preferences.order_query.mobile' => 'boolean',
'contact_preferences.order_query.sms' => 'boolean',
'contact_preferences.order_query.push' => 'boolean',
'contact_preferences.order_progress' => 'array',
'contact_preferences.order_progress.email' => 'boolean',
'contact_preferences.order_progress.sms' => 'boolean',
'contact_preferences.order_progress.push' => 'boolean',
'contact_preferences.offers_info' => 'array',
'contact_preferences.offers_info.post' => 'boolean',
'contact_preferences.offers_info.email' => 'boolean',
'contact_preferences.offers_info.mobile' => 'boolean',
'contact_preferences.offers_info.sms' => 'boolean',
'contact_preferences.offers_info.push' => 'boolean',
'attributes' => 'array',
'attributes.*.key' => ['required', Rule::in(array_keys(self::ATTRIBUTE_WHITELIST))],
'attributes.*.value' => 'required',
'house' => 'required|string|max:64',
'a_road' => 'string|max:32|nullable',
'b_road' => 'string|max:32|nullable',
'postcode' => 'required|max:16',
'town' => 'required|max:32|string',
'county' => 'string|max:32|nullable',
'country' => 'required|exists:main.data_countries,dco_uid',
]
}
/**
* Get the request data in a formatted array.
*
* @return array
*/
public function getRequestData()
{
$data = [
'user' => $this->getUserStringFromRequest(),
'siteId' => $this->header('Toolstation-Site-Id'),
'date' => Carbon::now(),
'username' => $this->get('username'),
'title' => $this->get('title'),
'firstName' => $this->get('first_name'),
'lastName' => $this->get('last_name'),
'telephone' => $this->get('telephone', ''),
'mobile' => $this->get('mobile', ''),
'email' => $this->get('email'),
'company' => $this->get('company', ''),
'jobTitle' => $this->get('job_title', ''),
'attributes' => collect($this->get('attributes', []))->map(function ($attribute) {
return [
'key' => self::ATTRIBUTE_WHITELIST[$attribute['key']],
'value' => $attribute['value'],
];
})->toArray(),
'contactPreferences' => $this->get('contact_preferences', []),
'house' => $this->get('house', ''),
'aRoad' => $this->get('a_road', ''),
'bRoad' => $this->get('b_road', ''),
'postcode' => $this->get('postcode'),
'town' => $this->get('town'),
'county' => $this->get('county', ''),
'country' => $this->get('country'),
];
}
CustomerCatalogueRequest Overview
The CustomerCatalogueRequest class is a custom request class that handles the validation and processing of customer catalogue requests. It extends the CustomerRequest class and is used to validate and prepare data for a customer catalogue request. The class uses various services and rules to validate the request data and ensure that it conforms to the required format. The class also provides a method for retrieving the request data in a formatted array.
Request Structure
- Authorization Method: Checks if the user is authenticated to make the request.
- Validation Rules: The rules method defines validation rules for the request data:
The customer_id field is required.The address_id field is required.
- Request Data Formatting: The getRequestData method returns an array containing the formatted request data. The array contains the following keys:
customer_id: The ID of the customer.address_id: The ID of the address.
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'customer_id' => 'required',
'address_id' => 'required',
];
}
/**
* Get the request data in a formatted array.
*
* @return array
*/
public function getRequestData()
{
return [
'customerId' => $this->get('customer_id'),
'addressId' => $this->get('address_id'),
'date' => Carbon::now()
];
}
CustomerContactUsRequest Overview
The CustomerContactUsRequest class is a custom request class that handles the validation and processing of customer contact requests. It extends the CustomerRequest class and is used to validate and prepare data for a customer contact request. The class uses various services and rules to validate the request data and ensure that it conforms to the required format. The class also provides a method for retrieving the request data in a formatted array.
Request Structure
- Authorization Method: Checks if the user is authenticated to make the request.
- Validation Rules: The rules method defines validation rules for the request data:
The id field is required.
- Request Data Formatting: The getRequestData method returns an array containing the formatted request data. The array contains the following keys:
user=> $this->getUserStringFromRequest(),date=> Carbon::now()
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'id' => 'required',
];
}
/**
* Get the request data in a formatted array.
*
* @return array
*/
public function getRequestData()
{
return [
'user' => $this->getUserStringFromRequest(),
'date' => Carbon::now()
];
}
CustomerRequest Overview
The CustomerRequest class is a custom request class that serves as the base class for handling customer-related requests. It provides common functionality and methods that are shared across different customer request classes. The class defines an authorization method to check if the user is authenticated to make the request and includes a method to retrieve the user string from the request. The class also extends the BaseRequest class, which provides additional functionality for handling requests.
Request Structure
- Authorization Method: Checks if the user is authenticated to make the request.
- Request Data Formatting: The getRequestData method returns an array containing the formatted request data. The array contains the following keys:
user=> $this->getUserStringFromRequest(),date=> Carbon::now()
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
}
/**
* Get the request data in a formatted array.
*
* @return array
*/
public function getRequestData()
{
return [
'user' => $this->getUserStringFromRequest(),
'date' => Carbon::now()
];
}
CustomerSignatureRequest Overview
The CustomerSignatureRequest class is a custom request class that handles the validation of customer signature requests. It extends the CustomerRequest class and is used to validate and process data related to customer signatures. The class includes validation rules to ensure that the request data is in the correct format and provides a method for retrieving the request data in a formatted array.
Request Structure
- Authorization Method: Checks if the user is authenticated to make the request.
- Request Data Formatting: The getRequestData method returns an array containing the formatted request data. The array contains the following keys:
name=> 'required',email=> 'required',companyName=> 'required',
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
}
/**
* Get the request data in a formatted array.
*
* @return array
*/
public function getRequestData()
{
return [
'name' => 'required',
'email' => 'required|email',
'companyName' => 'required',
];
}
DeleteCustomerAttributeRequest Overview
The DeleteCustomerAttributeRequest class is a custom request class that handles the validation and processing of customer attribute deletion requests. It extends the CustomerRequest class and is used to validate and prepare data for deleting a customer attribute. The class includes validation rules to ensure that the request data is in the correct format and provides a method for retrieving the request data in a formatted array.
Request Structure
- Authorization Method: Checks if the user is authenticated to make the request.
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
}
PatchCustomerAddressRequest Overview
The PatchCustomerAddressRequest class is a custom request class that handles the validation and processing of customer address update requests. It extends the CustomerRequest class and is used to validate and prepare data for updating a customer's address. The class includes validation rules to ensure that the request data is in the correct format and provides a method for retrieving the request data in a formatted array.
Request Structure
- Authorization Method: Checks if the user is authenticated to make the request.
- Validation Rules: The rules method defines validation rules for the request data:
house=> 'string|max:64|regex:/^a-zA-Z0-9_'.?!, -&/{1,}$/',a_road=> 'string|max:32|nullable',b_road=> 'string|max:32|nullable',postcode=> 'max:16|regex:/^a-zA-Z0-9{1,}$/',town=> 'max:32|string',county=> 'string|max:32|nullable',country_id=> 'exists:main.data_countries,dco_uid',type=> 'numeric|in:1,2,3'
- Request Data Formatting: The getRequestData method returns an array containing the formatted request data. The array contains the following keys:
user=> $this->getUserStringFromRequest(),date=> Carbon::now(),type=> $type->get('type');house=> $type->get('house');a_road=> $type->get('a_road');b_road=> $type->get('b_road');postcode=> $type->get('postcode');town=> $type->get('town');county=> $type->get('county');country_id=> $type->get('country_id');
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'house' => 'string|max:64|regex:/^[a-zA-Z0-9_\'\.\?\!\, \-\&\/]{1,}$/',
'a_road' => 'string|max:32|nullable',
'b_road' => 'string|max:32|nullable',
'postcode' => 'max:16|regex:/^[a-zA-Z0-9 ]{1,}$/',
'town' => 'max:32|string',
'county' => 'string|max:32|nullable',
'country_id' => 'exists:main.data_countries,dco_uid',
'type' => 'numeric|in:1,2,3'
];
}
/**
* Get the request data in a formatted array.
*
* @return array
*/
public function getRequestData()
{
return [
'user' => $this->getUserStringFromRequest(),
'date' => Carbon::now(),
'type' => $this->get('type'),
'house' => $this->get('house'),
'aRoad' => $this->get('a_road'),
'bRoad' => $this->get('b_road'),
'postcode' => $this->get('postcode'),
'town' => $this->get('town'),
'county' => $this->get('county'),
'countryId' => $this->get('country_id'),
'type' => $this->get('type'),
];
}
UpdateCustomerAddressRequest Overview
The UpdateCustomerAddressRequest class is a custom request class that handles the validation and processing of customer address update requests. It extends the CustomerRequest class and is used to validate and prepare data for updating a customer's address. The class includes validation rules to ensure that the request data is in the correct format and provides a method for retrieving the request data in a formatted array.
Request Structure
- Authorization Method: Checks if the user is authenticated to make the request.
- Validation Rules: The rules method defines validation rules for the request data:
house=> 'string|max:64|regex:/^a-zA-Z0-9_'.?!, -&/{1,}$/',a_road=> 'string|max:32|nullable',b_road=> 'string|max:32|nullable',postcode=> 'max:16|regex:/^a-zA-Z0-9{1,}$/',town=> 'max:32|string',county=> 'string|max:32|nullable',
- Request Data Formatting: The getRequestData method returns an array containing the formatted request data. The array contains the following keys:
user=> $this->getUserStringFromRequest(),date=> Carbon::now(),house=> $type->get('house'),a_road=> $type->get('a_road'),b_road=> $type->get('b_road'),postcode=> $type->get('postcode'),town=> $type->get('town'),county=> $type->get('county'),
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'house' => 'string|max:64|regex:/^[a-zA-Z0-9_\'\.\?\!\, \-\&\/]{1,}$/',
'a_road' => 'string|max:32|nullable',
'b_road' => 'string|max:32|nullable',
'postcode' => 'max:16|regex:/^[a-zA-Z0-9 ]{1,}$/',
'town' => 'max:32|string',
'county' => 'string|max:32|nullable',
];
}
/**
* Get the request data in a formatted array.
*
* @return array
*/
public function getRequestData()
{
return [
'user' => $this->getUserStringFromRequest(),
'date' => Carbon::now(),
'house' => $this->get('house'),
'aRoad' => $this->get('a_road'),
'bRoad' => $this->get('b_road'),
'postcode' => $this->get('postcode'),
'town' => $this->get('town'),
'county' => $this->get('county'),
];
}
UpdateCustomerIssueNotRequest Overview
The UpdateCustomerIssueNotRequest class is a custom request class that handles the validation and processing of customer issue note update requests. It extends the CustomerRequest class and is used to validate and prepare data for updating a customer issue note. The class includes validation rules to ensure that the request data is in the correct format and provides a method for retrieving the request data in a formatted array.
Request Structure
- Authorization Method: Checks if the user is authenticated to make the request.
- Validation Rules: The rules method defines validation rules for the request data:
The urgent field is required.
- Request Data Formatting: The getRequestData method returns an array containing the formatted request data. The array contains the following keys:
urgent=> $type->get('urgent'),
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'urgent' => 'required',
];
}
/**
* Get the request data in a formatted array.
*
* @return array
*/
public function getRequestData()
{
$data = [];
if ($this->has('urgent')) {
$data['urgent'] = (int) $this->get('urgent');
}
}
UpdateCustomerIssueRequest Overview
The UpdateCustomerIssueRequest class is a custom request class that handles the validation and processing of customer issue update requests. It extends the CustomerRequest class and is used to validate and prepare data for updating a customer's issue. The class includes validation rules to ensure that the request data is in the correct format and provides a method for retrieving the request data in a formatted array.
Request Structure
- Authorization Method: Checks if the user is authenticated to make the request.
- Validation Rules: The rules method defines validation rules for the request data:
The comment field is required.The urgent field is required.The completed field is required.
- Request Data Formatting: The getRequestData method returns an array containing the formatted request data. The array contains the following keys:
comment=> $type->get('comment'),urgent=> $type->get('urgent'),completed=> $type->get('completed'),
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'comment' => 'required',
'urgent' => 'required',
'completed' => 'required',
];
}
/**
* Get the request data in a formatted array.
*
* @return array
*/
public function getRequestData()
{
return [
'user' => $this->getUserStringFromRequest(),
'date' => Carbon::now(),
'comment' => $this->get('comment'),
'urgent' => $this->get('urgent'),
'completed' => $this->get('completed'),
'resolutionType' => $this->get('resolution_type'),
];
}
UpdateCustomerNoteRequest Overview
The UpdateCustomerNoteRequest class is a custom request class that handles the validation and processing of customer note update requests. It extends the CustomerRequest class and is used to validate and prepare data for updating a customer note. The class includes validation rules to ensure that the request data is in the correct format and provides a method for retrieving the request data in a formatted array.
Request Structure
- Authorization Method: Checks if the user is authenticated to make the request.
- Validation Rules: The rules method defines validation rules for the request data:
The urgent field is required.
- Request Data Formatting: The getRequestData method returns an array containing the formatted request data. The array contains the following keys:
urgent=> $type->get('urgent')
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
$data = [];
if ($this->has('urgent')) {
$data['urgent'] = (int) $this->get('urgent');
}
}
UpdateCustomerRequest Overview
The UpdateCustomerRequest class is a custom request class that handles the validation and processing of customer update requests. It extends the CustomerRequest class and is used to validate and prepare data for updating a customer. The class includes validation rules to ensure that the request data is in the correct format and provides a method for retrieving the request data in a formatted array.
Request Structure
- Authorization Method: Checks if the user is authenticated to make the request.
- Validation Rules: The rules method defines validation rules for the request data:
- `username` => 'email|unique:main.user_customers,ucu_username|string|max:64', - `title` => 'required|string|max:32', - `first_name` => 'required|string|max:32', - `last_name` => 'required|string|max:32', - `telephone` => 'string|max:32', - `mobile` => 'string|max:32', - `email` => 'email|max:254', - `company` => 'string|max:32', - `job_title` => 'string|max:32', - `vat_number` => 'string|max:100', - `contact_preferences` => 'array', - `contact_preferences.mail_catalogues` => 'boolean', - `contact_preferences.order_query` => 'array', - `contact_preferences.order_query.email` => 'boolean', - `contact_preferences.order_query.telephone` => 'boolean', - `contact_preferences.order_query.mobile` => 'boolean', - `contact_preferences.order_query.sms` => 'boolean', - `contact_preferences.order_query.push` => 'boolean', - `contact_preferences.order_progress` => 'array', - `contact_preferences.order_progress.email` => 'boolean', - `contact_preferences.order_progress.sms` => 'boolean', - `contact_preferences.order_progress.push` => 'boolean', - `contact_preferences.offers_info` => 'array', - `contact_preferences.offers_info.post` => 'boolean', - `contact_preferences.offers_info.email` => 'boolean', - `contact_preferences.offers_info.mobile` => 'boolean', - `contact_preferences.offers_info.sms` => 'boolean', - `contact_preferences.offers_info.push` => 'boolean', - `attributes` => 'array', - `attributes.*.key` => ['required', Rule::in(array_keys(self::ATTRIBUTE_WHITELIST))], - `attributes.*.value` => 'required', - `house` => 'required|string|max:64', - `a_road` => 'string|max:32|nullable', - `b_road` => 'string|max:32|nullable', - `postcode` => 'required|max:16', - `town` => 'required|max:32|string', - `county` => 'string|max:32|nullable',
Request Data Formatting: The getRequestData method returns an array containing the formatted request data. The array contains the following keys:
urgent=> $type->get('urgent')user=> $this->getUserStringFromRequest(),date=> Carbon::now(),type=> $this->get('type'),
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'username' => 'email|unique:main.user_customers,ucu_username|string|max:64',
'title' => 'required|string|max:32',
'first_name' => 'required|string|max:32',
'last_name' => 'required|string|max:32',
'telephone' => 'string|max:32',
'mobile' => 'string|max:32',
'email' => 'email|max:254',
'company' => 'string|max:32',
'job_title' => 'string|max:32',
'vat_number' => 'string|max:100',
'contact_preferences' => 'array',
'contact_preferences.mail_catalogues' => 'boolean',
'contact_preferences.order_query' => 'array',
'contact_preferences.order_query.email' => 'boolean',
'contact_preferences.order_query.telephone' => 'boolean',
'contact_preferences.order_query.mobile' => 'boolean',
'contact_preferences.order_query.sms' => 'boolean',
'contact_preferences.order_query.push' => 'boolean',
'contact_preferences.order_progress' => 'array',
'contact_preferences.order_progress.email' => 'boolean',
'contact_preferences.order_progress.sms' => 'boolean',
'contact_preferences.order_progress.push' => 'boolean',
'contact_preferences.offers_info' => 'array',
'contact_preferences.offers_info.post' => 'boolean',
'contact_preferences.offers_info.email' => 'boolean',
'contact_preferences.offers_info.mobile' => 'boolean',
'contact_preferences.offers_info.sms' => 'boolean',
'contact_preferences.offers_info.push' => 'boolean',
'attributes' => 'array',
'attributes.*.key' => ['required', Rule::in(array_keys(self::ATTRIBUTE_WHITELIST))],
'attributes.*.value' => 'required',
'house' => 'required|string|max:64',
'a_road' => 'string|max:32|nullable',
'b_road' => 'string|max:32|nullable',
];
}