Laravel - Sending data to an API via an object
I am using Laravel within a project, in this project I have to send data to an API endpoint in a JSON encoded array using specific key names.
As the user fills in a form, I am persisting the data to a model called Onboard
as it stores data necessary to onboard a client via an API I'm using, the table looks like this:
Schema::create('onboardings', function (Blueprint $table) {
$table->increments('id');
$table->timestamps();
$table->integer('user_id');
$table->text('email_type')->nullable();
$table->text('date_of_birth')->nullable();
$table->text('country_of_birth')->nullable();
$table->text('national_insurance_number')->nullable();
$table->text('country_of_residency')->nullable();
$table->text('tax_identification_number')->nullable();
$table->boolean('politically_exposed_person')->nullable();
$table->text('address_line_1')->nullable();
$table->text('address_line_2')->nullable();
$table->text('city')->nullable();
$table->text('county')->nullable();
$table->text('postcode')->nullable();
$table->text('country')->nullable();
$table->text('telephone_type')->nullable();
$table->text('dialing_code')->nullable();
$table->text('telephone_number')->nullable();
$table->text('account_name')->nullable();
$table->text('account_number')->nullable();
$table->text('sort_code')->nullable();
$table->text('investment_type')->nullable();
$table->text('investment_amount')->nullable();
$table->boolean('independent_financial_advisor')->nullable();
$table->boolean('understand_objective')->nullable();
$table->boolean('confirm_objective')->nullable();
$table->boolean('understand_term_held')->nullable();
$table->boolean('tax_relief')->nullable();
});
So, a user fills in a form and this table is filled with data.
The providers of the API gave me an example class to encapsulate all of the necessary data, as seen below.
<?php
class OnboardingClientDetails {
//[Required]
public $Title = "Ms.";
//[Required]
public $Forenames = "Beatrice";
//[Required]
public $Surname = "Volk";
//[Required] (Between 1 and 244)
public $CountryOfBirth = 1;
//[Required]
public $EmailAddress = "BeatriceJVolk@dayrep.com";
//[Required]
public $EmailType = "Work";
//[Required]
public $BirthDate;
public $Suffix = "";
public $NationalInsuranceNumber = "NITESTValue";
//[Required]
public $PrimaryAddress;
public $AdditionalAddresses;
//[Required]
public $PrimaryTelephone;
public $AdditionalTelephone;
//[Required]
public $BankAccount;
//[Required]
public $PrimaryCitizenship;
public $AdditionalCitizenship;
//[Required]
public $ExternalCustomerId = "12345";
//[Required]
public $ExternalPlanId = "P4541";
public $PlanType = 10;
public $MiddleNames = "W";
public $PlaceOfBirth = "London";
public $OnlineValuation = true;
public $PrincipalNationality;
public $AdditionalNationality;
function __construct()
{
$this->BirthDate = "/Date(". strtotime("10 September 1977") . ")/";
$this->PrimaryAddress = new Address();
$this->AdditionalAddresses = array(new Address(),new Address());
$this->PrimaryTelephone = new OnboardingTelephoneNumber();
$this->AdditionalTelephone = array(new OnboardingTelephoneNumber(),new OnboardingTelephoneNumber());
$this->BankAccount = new OnboardingBankAccount();
$this->PrimaryCitizenship = new OnboardingCitizenship();
$this->AdditionalCitizenship = array (new OnboardingCitizenship(),new OnboardingCitizenship());
$this->PrincipalNationality = new OnboardingPrincipalNationality();
$this->AdditionalNationality = new OnboardingPrincipalNationality();
}
}
class Address {
//[Required]
public $Address1 = "17 Moorgate";
public $Address2 = "";
//[Required]
public $City = "London";
public $County = "";
//[Required]
public $Postcode = "ec2r 6ar";
//[Required]
//Between 1 and 244
public $Country = 4;
//[Required]
public $AddressType = 1;
}
class OnboardingCitizenship
{
public $CountryOfResidency = 1;
public $TaxIdentificationNumber ="445010101";
}
class OnboardingTelephoneNumber {
//[Required]
public $Number = "5048491752";
//[Required]
public $DialingCode = "44";
//[Required]
public $TelephoneType = "1";
}
class OnboardingBankAccount {
//[Required]
public $AccountName = "Beatrice Volk";
//[Required]
public $AccountNumber = "7659708042";
//[Required]
public $SortCode = "010101";
}
class OnboardingPrincipalNationality {
public $CountryId = 1;
public $PrincipalNCI = "P434523";
public $PrincipalNationalityType = "Primary";
}
?>
In order to match this format I created an array with a combination of what's stored in both my user and onboarding table:
$userData = auth()->user()->first();
// dd($userData);
$submissionData = array(
"Title" => $userData->title,
"Forenames" => $userData->first_name,
"Surname" => $userData->last_name,
"CountryOfBirth" => $userData->onboarding->country_of_birth,
"EmailAddress" => $userData->email,
"EmailType" => $userData->onboarding->email_type,
"BirthDate" => "/Date(". strtotime($userData->onboarding->date_of_birth) . ")/",
"Suffix" => null,
"PrimaryAddress" => array(
"Address1" => $userData->onboarding->address_line_1,
"Address2" => $userData->onboarding->address_line_2,
"City" => $userData->onboarding->city,
"County" => $userData->onboarding->county,
"Postcode" => $userData->onboarding->postcode,
"Country" => $userData->onboarding->country
),
"AdditionalAddresses" => array(
array(
"Address1" => null,
"Address2" => null,
"City" => null,
"County" => null,
"Postcode" => null,
"Country" => 0,
"AddressType" => 0
)
),
"PrimaryTelephone" => array(
"Number" => $userData->onboarding->telephone_number,
"DialingCode" => $userData->onboarding->dialing_code,
"TelephoneType" => $userData->onboarding->telephone_type
),
"AdditionalTelephone" => array(
array(
"Number" => "123456789",
"DialingCode" => 1,
"TelephoneType" => 1
)
),
"BankAccount" => array(
"AccountName" => $userData->onboarding->account_name,
"AccountNumber" => $userData->onboarding->account_number,
"SortCode" => $userData->onboarding->sort_code
),
"PrimaryCitizenship" => array(
"CountryOfResidency" => $userData->onboarding->country_of_residency,
"TaxIdentificationNumber" => $userData->onboarding->tax_identification_number
),
"AdditionalCitizenship" => array(
array(
"CountryOfResidency" => 0,
"TaxIdentificationNumber" => null
)
),
"ExternalCustomerId" => rand(100, 10000),
"ExternalPlanId" => "151",
"PlanType" => 10
However, this feels like a very unclean way of doing things, so, whats the best way to deal with PHP classes that only hold data in Laravel?
php laravel api
add a comment |
I am using Laravel within a project, in this project I have to send data to an API endpoint in a JSON encoded array using specific key names.
As the user fills in a form, I am persisting the data to a model called Onboard
as it stores data necessary to onboard a client via an API I'm using, the table looks like this:
Schema::create('onboardings', function (Blueprint $table) {
$table->increments('id');
$table->timestamps();
$table->integer('user_id');
$table->text('email_type')->nullable();
$table->text('date_of_birth')->nullable();
$table->text('country_of_birth')->nullable();
$table->text('national_insurance_number')->nullable();
$table->text('country_of_residency')->nullable();
$table->text('tax_identification_number')->nullable();
$table->boolean('politically_exposed_person')->nullable();
$table->text('address_line_1')->nullable();
$table->text('address_line_2')->nullable();
$table->text('city')->nullable();
$table->text('county')->nullable();
$table->text('postcode')->nullable();
$table->text('country')->nullable();
$table->text('telephone_type')->nullable();
$table->text('dialing_code')->nullable();
$table->text('telephone_number')->nullable();
$table->text('account_name')->nullable();
$table->text('account_number')->nullable();
$table->text('sort_code')->nullable();
$table->text('investment_type')->nullable();
$table->text('investment_amount')->nullable();
$table->boolean('independent_financial_advisor')->nullable();
$table->boolean('understand_objective')->nullable();
$table->boolean('confirm_objective')->nullable();
$table->boolean('understand_term_held')->nullable();
$table->boolean('tax_relief')->nullable();
});
So, a user fills in a form and this table is filled with data.
The providers of the API gave me an example class to encapsulate all of the necessary data, as seen below.
<?php
class OnboardingClientDetails {
//[Required]
public $Title = "Ms.";
//[Required]
public $Forenames = "Beatrice";
//[Required]
public $Surname = "Volk";
//[Required] (Between 1 and 244)
public $CountryOfBirth = 1;
//[Required]
public $EmailAddress = "BeatriceJVolk@dayrep.com";
//[Required]
public $EmailType = "Work";
//[Required]
public $BirthDate;
public $Suffix = "";
public $NationalInsuranceNumber = "NITESTValue";
//[Required]
public $PrimaryAddress;
public $AdditionalAddresses;
//[Required]
public $PrimaryTelephone;
public $AdditionalTelephone;
//[Required]
public $BankAccount;
//[Required]
public $PrimaryCitizenship;
public $AdditionalCitizenship;
//[Required]
public $ExternalCustomerId = "12345";
//[Required]
public $ExternalPlanId = "P4541";
public $PlanType = 10;
public $MiddleNames = "W";
public $PlaceOfBirth = "London";
public $OnlineValuation = true;
public $PrincipalNationality;
public $AdditionalNationality;
function __construct()
{
$this->BirthDate = "/Date(". strtotime("10 September 1977") . ")/";
$this->PrimaryAddress = new Address();
$this->AdditionalAddresses = array(new Address(),new Address());
$this->PrimaryTelephone = new OnboardingTelephoneNumber();
$this->AdditionalTelephone = array(new OnboardingTelephoneNumber(),new OnboardingTelephoneNumber());
$this->BankAccount = new OnboardingBankAccount();
$this->PrimaryCitizenship = new OnboardingCitizenship();
$this->AdditionalCitizenship = array (new OnboardingCitizenship(),new OnboardingCitizenship());
$this->PrincipalNationality = new OnboardingPrincipalNationality();
$this->AdditionalNationality = new OnboardingPrincipalNationality();
}
}
class Address {
//[Required]
public $Address1 = "17 Moorgate";
public $Address2 = "";
//[Required]
public $City = "London";
public $County = "";
//[Required]
public $Postcode = "ec2r 6ar";
//[Required]
//Between 1 and 244
public $Country = 4;
//[Required]
public $AddressType = 1;
}
class OnboardingCitizenship
{
public $CountryOfResidency = 1;
public $TaxIdentificationNumber ="445010101";
}
class OnboardingTelephoneNumber {
//[Required]
public $Number = "5048491752";
//[Required]
public $DialingCode = "44";
//[Required]
public $TelephoneType = "1";
}
class OnboardingBankAccount {
//[Required]
public $AccountName = "Beatrice Volk";
//[Required]
public $AccountNumber = "7659708042";
//[Required]
public $SortCode = "010101";
}
class OnboardingPrincipalNationality {
public $CountryId = 1;
public $PrincipalNCI = "P434523";
public $PrincipalNationalityType = "Primary";
}
?>
In order to match this format I created an array with a combination of what's stored in both my user and onboarding table:
$userData = auth()->user()->first();
// dd($userData);
$submissionData = array(
"Title" => $userData->title,
"Forenames" => $userData->first_name,
"Surname" => $userData->last_name,
"CountryOfBirth" => $userData->onboarding->country_of_birth,
"EmailAddress" => $userData->email,
"EmailType" => $userData->onboarding->email_type,
"BirthDate" => "/Date(". strtotime($userData->onboarding->date_of_birth) . ")/",
"Suffix" => null,
"PrimaryAddress" => array(
"Address1" => $userData->onboarding->address_line_1,
"Address2" => $userData->onboarding->address_line_2,
"City" => $userData->onboarding->city,
"County" => $userData->onboarding->county,
"Postcode" => $userData->onboarding->postcode,
"Country" => $userData->onboarding->country
),
"AdditionalAddresses" => array(
array(
"Address1" => null,
"Address2" => null,
"City" => null,
"County" => null,
"Postcode" => null,
"Country" => 0,
"AddressType" => 0
)
),
"PrimaryTelephone" => array(
"Number" => $userData->onboarding->telephone_number,
"DialingCode" => $userData->onboarding->dialing_code,
"TelephoneType" => $userData->onboarding->telephone_type
),
"AdditionalTelephone" => array(
array(
"Number" => "123456789",
"DialingCode" => 1,
"TelephoneType" => 1
)
),
"BankAccount" => array(
"AccountName" => $userData->onboarding->account_name,
"AccountNumber" => $userData->onboarding->account_number,
"SortCode" => $userData->onboarding->sort_code
),
"PrimaryCitizenship" => array(
"CountryOfResidency" => $userData->onboarding->country_of_residency,
"TaxIdentificationNumber" => $userData->onboarding->tax_identification_number
),
"AdditionalCitizenship" => array(
array(
"CountryOfResidency" => 0,
"TaxIdentificationNumber" => null
)
),
"ExternalCustomerId" => rand(100, 10000),
"ExternalPlanId" => "151",
"PlanType" => 10
However, this feels like a very unclean way of doing things, so, whats the best way to deal with PHP classes that only hold data in Laravel?
php laravel api
add a comment |
I am using Laravel within a project, in this project I have to send data to an API endpoint in a JSON encoded array using specific key names.
As the user fills in a form, I am persisting the data to a model called Onboard
as it stores data necessary to onboard a client via an API I'm using, the table looks like this:
Schema::create('onboardings', function (Blueprint $table) {
$table->increments('id');
$table->timestamps();
$table->integer('user_id');
$table->text('email_type')->nullable();
$table->text('date_of_birth')->nullable();
$table->text('country_of_birth')->nullable();
$table->text('national_insurance_number')->nullable();
$table->text('country_of_residency')->nullable();
$table->text('tax_identification_number')->nullable();
$table->boolean('politically_exposed_person')->nullable();
$table->text('address_line_1')->nullable();
$table->text('address_line_2')->nullable();
$table->text('city')->nullable();
$table->text('county')->nullable();
$table->text('postcode')->nullable();
$table->text('country')->nullable();
$table->text('telephone_type')->nullable();
$table->text('dialing_code')->nullable();
$table->text('telephone_number')->nullable();
$table->text('account_name')->nullable();
$table->text('account_number')->nullable();
$table->text('sort_code')->nullable();
$table->text('investment_type')->nullable();
$table->text('investment_amount')->nullable();
$table->boolean('independent_financial_advisor')->nullable();
$table->boolean('understand_objective')->nullable();
$table->boolean('confirm_objective')->nullable();
$table->boolean('understand_term_held')->nullable();
$table->boolean('tax_relief')->nullable();
});
So, a user fills in a form and this table is filled with data.
The providers of the API gave me an example class to encapsulate all of the necessary data, as seen below.
<?php
class OnboardingClientDetails {
//[Required]
public $Title = "Ms.";
//[Required]
public $Forenames = "Beatrice";
//[Required]
public $Surname = "Volk";
//[Required] (Between 1 and 244)
public $CountryOfBirth = 1;
//[Required]
public $EmailAddress = "BeatriceJVolk@dayrep.com";
//[Required]
public $EmailType = "Work";
//[Required]
public $BirthDate;
public $Suffix = "";
public $NationalInsuranceNumber = "NITESTValue";
//[Required]
public $PrimaryAddress;
public $AdditionalAddresses;
//[Required]
public $PrimaryTelephone;
public $AdditionalTelephone;
//[Required]
public $BankAccount;
//[Required]
public $PrimaryCitizenship;
public $AdditionalCitizenship;
//[Required]
public $ExternalCustomerId = "12345";
//[Required]
public $ExternalPlanId = "P4541";
public $PlanType = 10;
public $MiddleNames = "W";
public $PlaceOfBirth = "London";
public $OnlineValuation = true;
public $PrincipalNationality;
public $AdditionalNationality;
function __construct()
{
$this->BirthDate = "/Date(". strtotime("10 September 1977") . ")/";
$this->PrimaryAddress = new Address();
$this->AdditionalAddresses = array(new Address(),new Address());
$this->PrimaryTelephone = new OnboardingTelephoneNumber();
$this->AdditionalTelephone = array(new OnboardingTelephoneNumber(),new OnboardingTelephoneNumber());
$this->BankAccount = new OnboardingBankAccount();
$this->PrimaryCitizenship = new OnboardingCitizenship();
$this->AdditionalCitizenship = array (new OnboardingCitizenship(),new OnboardingCitizenship());
$this->PrincipalNationality = new OnboardingPrincipalNationality();
$this->AdditionalNationality = new OnboardingPrincipalNationality();
}
}
class Address {
//[Required]
public $Address1 = "17 Moorgate";
public $Address2 = "";
//[Required]
public $City = "London";
public $County = "";
//[Required]
public $Postcode = "ec2r 6ar";
//[Required]
//Between 1 and 244
public $Country = 4;
//[Required]
public $AddressType = 1;
}
class OnboardingCitizenship
{
public $CountryOfResidency = 1;
public $TaxIdentificationNumber ="445010101";
}
class OnboardingTelephoneNumber {
//[Required]
public $Number = "5048491752";
//[Required]
public $DialingCode = "44";
//[Required]
public $TelephoneType = "1";
}
class OnboardingBankAccount {
//[Required]
public $AccountName = "Beatrice Volk";
//[Required]
public $AccountNumber = "7659708042";
//[Required]
public $SortCode = "010101";
}
class OnboardingPrincipalNationality {
public $CountryId = 1;
public $PrincipalNCI = "P434523";
public $PrincipalNationalityType = "Primary";
}
?>
In order to match this format I created an array with a combination of what's stored in both my user and onboarding table:
$userData = auth()->user()->first();
// dd($userData);
$submissionData = array(
"Title" => $userData->title,
"Forenames" => $userData->first_name,
"Surname" => $userData->last_name,
"CountryOfBirth" => $userData->onboarding->country_of_birth,
"EmailAddress" => $userData->email,
"EmailType" => $userData->onboarding->email_type,
"BirthDate" => "/Date(". strtotime($userData->onboarding->date_of_birth) . ")/",
"Suffix" => null,
"PrimaryAddress" => array(
"Address1" => $userData->onboarding->address_line_1,
"Address2" => $userData->onboarding->address_line_2,
"City" => $userData->onboarding->city,
"County" => $userData->onboarding->county,
"Postcode" => $userData->onboarding->postcode,
"Country" => $userData->onboarding->country
),
"AdditionalAddresses" => array(
array(
"Address1" => null,
"Address2" => null,
"City" => null,
"County" => null,
"Postcode" => null,
"Country" => 0,
"AddressType" => 0
)
),
"PrimaryTelephone" => array(
"Number" => $userData->onboarding->telephone_number,
"DialingCode" => $userData->onboarding->dialing_code,
"TelephoneType" => $userData->onboarding->telephone_type
),
"AdditionalTelephone" => array(
array(
"Number" => "123456789",
"DialingCode" => 1,
"TelephoneType" => 1
)
),
"BankAccount" => array(
"AccountName" => $userData->onboarding->account_name,
"AccountNumber" => $userData->onboarding->account_number,
"SortCode" => $userData->onboarding->sort_code
),
"PrimaryCitizenship" => array(
"CountryOfResidency" => $userData->onboarding->country_of_residency,
"TaxIdentificationNumber" => $userData->onboarding->tax_identification_number
),
"AdditionalCitizenship" => array(
array(
"CountryOfResidency" => 0,
"TaxIdentificationNumber" => null
)
),
"ExternalCustomerId" => rand(100, 10000),
"ExternalPlanId" => "151",
"PlanType" => 10
However, this feels like a very unclean way of doing things, so, whats the best way to deal with PHP classes that only hold data in Laravel?
php laravel api
I am using Laravel within a project, in this project I have to send data to an API endpoint in a JSON encoded array using specific key names.
As the user fills in a form, I am persisting the data to a model called Onboard
as it stores data necessary to onboard a client via an API I'm using, the table looks like this:
Schema::create('onboardings', function (Blueprint $table) {
$table->increments('id');
$table->timestamps();
$table->integer('user_id');
$table->text('email_type')->nullable();
$table->text('date_of_birth')->nullable();
$table->text('country_of_birth')->nullable();
$table->text('national_insurance_number')->nullable();
$table->text('country_of_residency')->nullable();
$table->text('tax_identification_number')->nullable();
$table->boolean('politically_exposed_person')->nullable();
$table->text('address_line_1')->nullable();
$table->text('address_line_2')->nullable();
$table->text('city')->nullable();
$table->text('county')->nullable();
$table->text('postcode')->nullable();
$table->text('country')->nullable();
$table->text('telephone_type')->nullable();
$table->text('dialing_code')->nullable();
$table->text('telephone_number')->nullable();
$table->text('account_name')->nullable();
$table->text('account_number')->nullable();
$table->text('sort_code')->nullable();
$table->text('investment_type')->nullable();
$table->text('investment_amount')->nullable();
$table->boolean('independent_financial_advisor')->nullable();
$table->boolean('understand_objective')->nullable();
$table->boolean('confirm_objective')->nullable();
$table->boolean('understand_term_held')->nullable();
$table->boolean('tax_relief')->nullable();
});
So, a user fills in a form and this table is filled with data.
The providers of the API gave me an example class to encapsulate all of the necessary data, as seen below.
<?php
class OnboardingClientDetails {
//[Required]
public $Title = "Ms.";
//[Required]
public $Forenames = "Beatrice";
//[Required]
public $Surname = "Volk";
//[Required] (Between 1 and 244)
public $CountryOfBirth = 1;
//[Required]
public $EmailAddress = "BeatriceJVolk@dayrep.com";
//[Required]
public $EmailType = "Work";
//[Required]
public $BirthDate;
public $Suffix = "";
public $NationalInsuranceNumber = "NITESTValue";
//[Required]
public $PrimaryAddress;
public $AdditionalAddresses;
//[Required]
public $PrimaryTelephone;
public $AdditionalTelephone;
//[Required]
public $BankAccount;
//[Required]
public $PrimaryCitizenship;
public $AdditionalCitizenship;
//[Required]
public $ExternalCustomerId = "12345";
//[Required]
public $ExternalPlanId = "P4541";
public $PlanType = 10;
public $MiddleNames = "W";
public $PlaceOfBirth = "London";
public $OnlineValuation = true;
public $PrincipalNationality;
public $AdditionalNationality;
function __construct()
{
$this->BirthDate = "/Date(". strtotime("10 September 1977") . ")/";
$this->PrimaryAddress = new Address();
$this->AdditionalAddresses = array(new Address(),new Address());
$this->PrimaryTelephone = new OnboardingTelephoneNumber();
$this->AdditionalTelephone = array(new OnboardingTelephoneNumber(),new OnboardingTelephoneNumber());
$this->BankAccount = new OnboardingBankAccount();
$this->PrimaryCitizenship = new OnboardingCitizenship();
$this->AdditionalCitizenship = array (new OnboardingCitizenship(),new OnboardingCitizenship());
$this->PrincipalNationality = new OnboardingPrincipalNationality();
$this->AdditionalNationality = new OnboardingPrincipalNationality();
}
}
class Address {
//[Required]
public $Address1 = "17 Moorgate";
public $Address2 = "";
//[Required]
public $City = "London";
public $County = "";
//[Required]
public $Postcode = "ec2r 6ar";
//[Required]
//Between 1 and 244
public $Country = 4;
//[Required]
public $AddressType = 1;
}
class OnboardingCitizenship
{
public $CountryOfResidency = 1;
public $TaxIdentificationNumber ="445010101";
}
class OnboardingTelephoneNumber {
//[Required]
public $Number = "5048491752";
//[Required]
public $DialingCode = "44";
//[Required]
public $TelephoneType = "1";
}
class OnboardingBankAccount {
//[Required]
public $AccountName = "Beatrice Volk";
//[Required]
public $AccountNumber = "7659708042";
//[Required]
public $SortCode = "010101";
}
class OnboardingPrincipalNationality {
public $CountryId = 1;
public $PrincipalNCI = "P434523";
public $PrincipalNationalityType = "Primary";
}
?>
In order to match this format I created an array with a combination of what's stored in both my user and onboarding table:
$userData = auth()->user()->first();
// dd($userData);
$submissionData = array(
"Title" => $userData->title,
"Forenames" => $userData->first_name,
"Surname" => $userData->last_name,
"CountryOfBirth" => $userData->onboarding->country_of_birth,
"EmailAddress" => $userData->email,
"EmailType" => $userData->onboarding->email_type,
"BirthDate" => "/Date(". strtotime($userData->onboarding->date_of_birth) . ")/",
"Suffix" => null,
"PrimaryAddress" => array(
"Address1" => $userData->onboarding->address_line_1,
"Address2" => $userData->onboarding->address_line_2,
"City" => $userData->onboarding->city,
"County" => $userData->onboarding->county,
"Postcode" => $userData->onboarding->postcode,
"Country" => $userData->onboarding->country
),
"AdditionalAddresses" => array(
array(
"Address1" => null,
"Address2" => null,
"City" => null,
"County" => null,
"Postcode" => null,
"Country" => 0,
"AddressType" => 0
)
),
"PrimaryTelephone" => array(
"Number" => $userData->onboarding->telephone_number,
"DialingCode" => $userData->onboarding->dialing_code,
"TelephoneType" => $userData->onboarding->telephone_type
),
"AdditionalTelephone" => array(
array(
"Number" => "123456789",
"DialingCode" => 1,
"TelephoneType" => 1
)
),
"BankAccount" => array(
"AccountName" => $userData->onboarding->account_name,
"AccountNumber" => $userData->onboarding->account_number,
"SortCode" => $userData->onboarding->sort_code
),
"PrimaryCitizenship" => array(
"CountryOfResidency" => $userData->onboarding->country_of_residency,
"TaxIdentificationNumber" => $userData->onboarding->tax_identification_number
),
"AdditionalCitizenship" => array(
array(
"CountryOfResidency" => 0,
"TaxIdentificationNumber" => null
)
),
"ExternalCustomerId" => rand(100, 10000),
"ExternalPlanId" => "151",
"PlanType" => 10
However, this feels like a very unclean way of doing things, so, whats the best way to deal with PHP classes that only hold data in Laravel?
php laravel api
php laravel api
asked Nov 21 '18 at 13:32
Jesse OrangeJesse Orange
599317
599317
add a comment |
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53413201%2flaravel-sending-data-to-an-api-via-an-object%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53413201%2flaravel-sending-data-to-an-api-via-an-object%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown