Laravel Array Value not store into database - mysql

I am trying to store array data but its giving me null value, I dont know what happend. Bellow the responses and my trial code:
Reponse Data:
Array
(
[0] => Array
(
[name] => facebook
)
[1] => Array
(
[url] => facebook
)
[2] => Array
(
[icon] => facebook
)
[3] => Array
(
[name] => linkedin
)
[4] => Array
(
[url] => linkedin
)
[5] => Array
(
[icon] => linkedin
)
)
Controller:
for ($i = 1; $i < count($request->fields); $i++) {
$socialitem[] = [
'name' => $request->fields['name'][$i],
'url' => $request->fields['url'][$i],
'icon' => $request->fields['icon'][$i],
'teams_id' => $team->id,
];
}
TeamsSocial_link::insert($socialitem);
My table:
$table->bigIncrements('id');
$table->string('name');
$table->string('url');
$table->string('icon')->nullable();
$table->bigInteger('teams_id')->unsigned();
I have try above code to store array data but its not working, I also research interet and try that way but still getting error.

it seems to me like you should do something like this
for ($i = 0; $i < count($request->fields); $i++) {
$socialitem = [
'name' => $request->fields[$i]['name'],
'url' => $request->fields[$i]['url'],
'icon' => $request->fields[$i]['icon'],
'teams_id' => $team->id,
];
TeamsSocial_link::insert($socialitem);
}
if you need only one item, no need for the loop
$socialitem = [
'name' => $request->fields[0]['name'],
'url' => $request->fields[1]['url'],
'icon' => $request->fields[2]['icon'],
'teams_id' => $team->id,
];
if you want to have multiple items
for ($i = 0; $i < count($request->fields) / 3; $i = $i+3) {
$socialitem = [
'name' => $request->fields[$i]['name'],
'url' => $request->fields[$i+1]['url'],
'icon' => $request->fields[$i+2]['icon'],
'teams_id' => $team->id,
];
TeamsSocial_link::insert($socialitem);
}

Related

one query for all array data! result is by separating for each id of array

I am searching all names for each transaction id.
Eg.,
id 1 have user A, B.
id 2 have user A.
id 3 have user A, C.
I can get user names which belong to each Id like that
foreach ($Ids in $id){
$query = [
'fields' => [
'USER.name'
],
'joins' => [
[
'type' => 'LEFT',
'table' => 'users',
'alias' => 'USER',
'conditions' => [
'TransactionUser.user_id=USER.id'
]
]
],
'conditions' => [
'TransactionUser.transaction_id' => $id
]
];
$this->find('all', $query);
}
But the problem is my leader don't want to loop query and want to do with only one query.
So I try like this.
$query = [
'fields' => [
'USER.name',
'TransactionUser.transaction_id'
],
'joins' => [
[
'type' => 'LEFT',
'table' => 'users',
'alias' => 'USER',
'conditions' => [
'TransactionUser.user_id=USER.id'
]
]
],
'conditions' => [
'TransactionUser.transaction_id' => $Ids
]
];
$this->find('all', $query);
It's work in cakePHP and result is like that.
Array
(
[0] => Array
( ([name] => A), ([transaction_id] => 1))
[1] => Array
( ([name] => B), ([transaction_id] => 1))
[2] => Array
( ([name] => A), ([transaction_id] => 2))
[3] => Array
( ([name] => A), ([transaction_id] => 3))
[4] => Array
( ([name] => C), ([transaction_id] => 3))
)
But I want data like that somehow.
Array
(
[0] => Array
( ([name] => A, B), ([transaction_id] => 1))
[1] => Array
( ([name] => A), ([transaction_id] => 2))
[2] => Array
( ([name] => A, C), ([transaction_id] => 3))
)
I try to use 'group' in query but it's not work well. I'm newbee in cakePHP query. Please help me if you know howto.
I just want to know some Query keyword of cakePHP for this case to be smart but it's look like not have.
So just loop result for desired array.

An Issue with saving SalesOrders data from REST API call to Exact Online

I have been using PHP Client library for Exact Online for a long time.
After saving the customer Accounts, Addresses, Contacts and then filtering out the PaymentConditions based on WooCommerce orders, items are successfully reflecting in the Exact Online dashboard.
But unfortunately calling the SalesOrders post request API. I'm unable to store into the Exact Online dashboard,
even though in order to store only OrderedBy itself is enough which is given in the official documentation
$ordersn = $order->save();
Picqer\Financials\Exact\ApiException : Error 403: Forbidden
$order = new SalesOrder($connection);
$lines = new SalesOrderLine($connection);
....
echo'<pre>'; print_r($order);
$order->SalesOrderLines = $lines;
$ordersn = $order->save();
if ($ordersn->ID)
{
$orderitem['sync_flag'] = true;
}
Here is the details of an order array
Picqer\Financials\Exact\SalesOrder Object
(
...
[attributes:protected] => Array
(
[WarehouseID] => 26ca2016-453f-499a-8a34-c986009bc78d
[OrderID] => FC290B7D-766B-4CBB-B7A2-47327AA3841F
[OrderedBy] => 764a4f6d-4b39-43b4-a86c-265e5478afbd
[DeliverTo] => 764a4f6d-4b39-43b4-a86c-265e5478afbd
[OrderDate] => 2019-02-17T19:29:53
[YourRef] => 75591901YP220320G
[OrderedByName] => Peter Kerner
[Description] => 16031_PayPal/Lastschrift/Kreditkarte
[Remarks] => Order is processing
[PaymentReference] => 16031
[PaymentCondition] =>
[SalesOrderLines] => Picqer\Financials\Exact\SalesOrderLine Object
(
[attributes:protected] => Array
(
[OrderID] => FC290B7D-766B-4CBB-B7A2-47327AA3841F
[VATAmount] => 5,58
[Description] => Goodies Box
[Quantity] => 1,00
[UnitPrice] => 29,37
[Item] => 418d43d6-55fe-410a-8df2-b05cbb72cea5
)
...
)
)
...
)
Do we need to upload VAT code or Am I missing something else data to be resided first shown from the above order-array or what else should we need to call appropriate API. Since in-order to reflect on the Exact Online dashboard. what should we need to follow?
From the built-In function call addItem() below snippets of code:
$soLines = array(
'OrderID' => $lines->OrderID,
'Item' => $lines->Item,
'Description' => $lines->Description,
'Quantity' => $lines->Quantity,
'UnitPrice' => $lines->UnitPrice,
'VATAmount' => $lines->VATAmount,
'VATCode' => $lines->VATCode
);
$order->addItem($soLines);
Generates the results with LineNumber to be included in SalesOrderLines array
[attributes:protected] => Array
(
[WarehouseID] => 26ca2016-453f-499a-8a34-c986009bc78d
[OrderID] => 65F93F56-97A8-4D54-AE37-C0BDDE774E67
[OrderedBy] => 9b048b81-f729-413a-b196-526436f11fe7
[DeliverTo] => 9b048b81-f729-413a-b196-526436f11fe7
[OrderDate] => 2019-02-17T20:45:34
[YourRef] => 9Y9593859V795183K
[OrderedByName] => Katrin Lenk
[Description] => 16033_PayPal Express
[Remarks] => Order is processing
[PaymentReference] => 16033
[PaymentCondition] =>
[SalesOrderLines] => Array
(
[0] => Array
(
[OrderID] => 65F93F56-97A8-4D54-AE37-C0BDDE774E67
[Item] => 5c415369-615c-4953-b28c-c7688f61cfaa
[Description] => ABC Classic
[Quantity] => 2,00
[UnitPrice] => 15,08
[VATAmount] => 5,73
[VATCode] =>
[LineNumber] => 1
)
)
)
Also note I haven't created Journals, GLAccounts, Documents & DocumentAttachments API. Does this actually affects storing of SalesOrders
EDIT:
In much simpler
$salesOrder = new \Picqer\Financials\Exact\SalesOrder($connection);
$salesOrder->WarehouseID = '26ca2016-453f-499a-8a34-c986009bc78d';
$salesOrder->OrderID = '65F93F56-97A8-4D54-AE37-C0BDDE774E67';
$salesOrder->OrderedBy = '9b048b81-f729-413a-b196-526436f11fe7';
$salesOrder->DeliverTo = '9b048b81-f729-413a-b196-526436f11fe7';
$salesOrder->OrderDate = '2019-02-17T20:45:34';
$salesOrder->YourRef = '9Y9593859V795183K';
$salesOrder->OrderedByName = 'Katrin Lenk';
$salesOrder->Description = '16033_PayPal Express';
$salesOrder->Remarks = 'Order is processing';
$salesOrder->PaymentReference = '16033';
$salesOrder->PaymentCondition = 'PP';
$soLines = array(
'Item' => '5c415369-615c-4953-b28c-c7688f61cfaa',
'Description' => 'ABC Classic',
'Quantity' => '1,00',
'UnitPrice' => '29,37',
'OrderID' => '65F93F56-97A8-4D54-AE37-C0BDDE774E67'
);
echo '<pre>'; print_r($soLines);
$salesOrder->addItem($soLines);
echo '<pre>'; print_r($salesOrder);
$salesOrder->save();
Resulting value stored from the soLines array
[attributes:protected] => Array
(
[WarehouseID] => 26ca2016-453f-499a-8a34-c986009bc78d
[OrderID] => 65F93F56-97A8-4D54-AE37-C0BDDE774E67
[OrderedBy] => 9b048b81-f729-413a-b196-526436f11fe7
[DeliverTo] => 9b048b81-f729-413a-b196-526436f11fe7
[OrderDate] => 2019-02-17T20:45:34
[YourRef] => 9Y9593859V795183K
[OrderedByName] => Katrin Lenk
[Description] => 16033_PayPal Express
[Remarks] => Order is processing
[PaymentReference] => 16033
[PaymentCondition] =>
[SalesOrderLines] => Array
(
[0] => Array
(
[OrderID] => 65F93F56-97A8-4D54-AE37-C0BDDE774E67
[Item] => 5c415369-615c-4953-b28c-c7688f61cfaa
[Description] => ABC Classic
[Quantity] => 2,00
[UnitPrice] => 15,08
[VATAmount] => 5,73
[VATCode] =>
[LineNumber] => 1
)
)
)
Actual Result:
Picqer\Financials\Exact\ApiException : Error 403: Forbidden
The reason was OrderID value was included twice in the SalesOrderLine as well as in SalesOrder for the two REST API calls and removing the OrderID entry from SalesOrder worked perfectly and reflecting in the Exact Online Dashboard
You cannot assign $order->SalesOrderLines = $lines; directly resulting in a collection to array error.
The only way to do this was to call via in-built function called addItem() passing array objects into it.

Unable to insert array into database

I am inserting multiple data from multiple forms into database but encounter an error at column photo
Unknown column 'Array' in 'field list'
Controller
if(!empty($_FILES['user_profile_file']['name'])){
$filesCount = count($_FILES['user_profile_file']['name']);
for ($i = 0; $i < $filesCount; $i++) {
$studentImg = '';
$_FILES['userFile']['name'] = $_FILES['user_profile_file']['name'][$i];
$_FILES['userFile']['type'] = $_FILES['user_profile_file']['type'][$i];
$_FILES['userFile']['tmp_name'] = $_FILES['user_profile_file']['tmp_name'][$i];
$_FILES['userFile']['error'] = $_FILES['user_profile_file']['error'][$i];
$_FILES['userFile']['size'] = $_FILES['user_profile_file']['size'][$i];
$config['upload_path'] = FCPATH."uploadfiles/users/student-img";
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = 0;
$studentImgNew = uniqueId();
$config['file_name'] = $studentImgNew;
$this->load->library('upload', $config);
if($this->upload->do_upload('userFile')){
$fileData = $this->upload->data();
$studentImg[$i]['photo'] = $fileData['file_name'];
$studentData[] = array(
'name' => $_POST['user_name'][$i],
'nric' => $_POST['user_nric'][$i],
'gender' => $_POST['user_gender'][$i],
'photo' => $studentImg,
'email' => $_POST['user_email'][$i],
'password' => md5($_POST['user_password'][$i]),
'is_active' => '0',
);
}
}
}
$this->User_account_model->create($studentData)
Model
function create($studentData){
foreach ($studentData as $key => $studentDatas) {
$insertStudentData[$key] = array(
'parent_id' => $parent_id,
'email' => $studentDatas['email'],
'password' => $studentDatas['password'],
'name' => $studentDatas['name'],
'nric' => $studentDatas['nric'],
'gender' => $studentDatas['gender'],
'photo' => $studentDatas['photo'],
'is_active' => $studentDatas['is_active'],
);
$this->db->insert('users_student', $insertStudentData[$key]);
}
if($this->db->affected_rows() != 1){
return false;
} else {
return true;
}
}
When I do print_r() I can get the exact data to be inserted into the database.
Array
(
[0] => Array
(
[parent_id] => 11
[email] => testing.mael#gmail.com
[password] => e02cb962ac59075b964b07152d234b70
[name] => testing
[nric] => 123123
[gender] => 0
[photo] => Array
(
[0] => Array
(
[photo] => 5955cac09b8f71.jpg
)
)
[is_active] => 0
)
[1] => Array
(
[parent_id] => 11
[email] => testing.mael#gmail.com
[password] => e13cc542ac59075b9643s5152d234g59
[name] => testing sister
[nric] => 123123
[gender] => 0
[photo] => Array
(
[0] => Array
(
[photo] => 5955cac09b8f72.jpg
)
)
[is_active] => 0
)
)
You are trying to insert an array inside the for insertStudentData[key].
Try This:
$insertStudentData[$key] = array(
'parent_id' => $parent_id,
'email' => $studentDatas['email'],
'password' => $studentDatas['password'],
'name' => $studentDatas['name'],
'nric' => $studentDatas['nric'],
'gender' => $studentDatas['gender'],
'photo' => $studentDatas['photo'],
'is_active' => $studentDatas['is_active']['0']['photo'],
);
$this->db->insert('users_student', $insertStudentData[$key]);
if you are trying to insert multiple rows, then you can use insert_batch
I have tried your code on my side and it gets perfectly correct. it added the multiple rows to the table. This is what I have done.
function create($studentData){
$insertStudentData = ''; //Create a Variable
foreach ($studentData => $studentDatas) {
$insertStudentData[] = array(
'parent_id' => $parent_id,
'email' => $studentDatas['email'],
'password' => $studentDatas['password'],
'name' => $studentDatas['name'],
'nric' => $studentDatas['nric'],
'gender' => $studentDatas['gender'],
'photo' => $studentDatas['photo']['0']['photo'],
'is_active' => $studentDatas['is_active']
);
}
$this->db->insert_batch('users_student', $insertStudentData[$key]);
if($this->db->affected_rows() != 1){
return false;
} else {
return true;
}
}
Finally I solved my issue. From my controller I changed the assigning array like this :
if($this->upload->do_upload('userFile')){
$fileData = $this->upload->data();
$studentImg[$i]['photo'] = $fileData['file_name'];
$studentData[] = array(
'name' => $_POST['user_name'][$i],
'nric' => $_POST['user_nric'][$i],
'gender' => $_POST['user_gender'][$i],
'photo' => $studentImg[$i]['photo'], // Edited row
'email' => $_POST['user_email'][$i],
'password' => md5($_POST['user_password'][$i]),
'is_active' => '0',
);
}
And my foreach model I changed to this :
foreach ($studentData as $studentDatas) {
$insertStudentData[] = array(
'parent_id' => $parent_id,
'email' => $studentDatas['email'],
'password' => $studentDatas['password'],
'name' => $studentDatas['name'],
'nric' => $studentDatas['nric'],
'gender' => $studentDatas['gender'],
'photo' => $studentDatas['photo'],
'is_active' => $studentDatas['is_active'],
);
}
$this->db->insert_batch('users_student', $insertStudentData);
And the output of those array :
Array
(
[0] => Array
(
[parent_id] => 11
[email] => testing.mael#gmail.com
[password] => 202cb962ac59075b964b07152d234b70
[name] => testing
[nric] => 123123
[gender] => 0
[photo] => 5955cac09b8f71.jpg
[is_active] => 0
)
[1] => Array
(
[parent_id] => 11
[email] => testing.mael#gmail.com
[password] => e13cc542ac59075b9643s5152d234g59
[name] => testing sister
[nric] => 123123
[gender] => 0
[photo] => 5955cac09b8f72.jpg
[is_active] => 0
)
)
By the way, thank you for everyone that trying to help! I appreciate it.

Facebook AdSet API "Your Budget is Too Low" error

Problem
I made a request to Facebook's Ad Set API attempting to create an ad set with the following JSON blob, and the error I received was "Your Budget Is Too Low. The minimum budget for this ad set is $32.04."
The ad set is set to use auto_bid and a valid lifetime_target. The ad set runs for 31 days, and with a $1 minimum daily budget, setting $64 for lifetime budget should've been sufficient.
Attempted Solutions
I tried to set a higher lifetime budget: from 64 to 1000 to 5000. 1000 did not work in this case, but 5000 did.
JSON Blob Used
Array
(
[account_id] =>
[adset_schedule] =>
[bid_amount] =>
[billing_event] => IMPRESSIONS
[budget_remaining] =>
[campaign_id] => 6054825216096
[created_time] =>
[creative_sequence] =>
[daily_budget] =>
[end_time] => 2016-11-08T07:59:59+0000
[id] =>
[is_autobid] => 1
[lifetime_budget] => 64
[lifetime_imps] =>
[name] => Some-Test-Campaign
[optimization_goal] => LINK_CLICKS
[pacing_type] =>
[recommendations] =>
[rf_prediction_id] =>
[start_time] => 2016-10-07T07:00:00+0000
[updated_time] =>
[targeting] => FacebookAds\Object\TargetingSpecs Object
(
[data:protected] => Array
(
[genders] =>
[age_min] =>
[age_max] =>
[geo_locations] => Array
(
[zips] => Array
(
[0] => Array
(
[key] => US:98004
)
[1] => Array
(
[key] => US:98005
)
[2] => Array
(
[key] => US:98006
)
[3] => Array
(
[key] => US:98007
)
[4] => Array
(
[key] => US:98008
)
[5] => Array
(
[key] => US:98009
)
[6] => Array
(
[key] => US:98011
)
[7] => Array
(
[key] => US:98014
)
[8] => Array
(
[key] => US:98015
)
[9] => Array
(
[key] => US:98019
)
[10] => Array
(
[key] => US:98021
)
)
)
[geo_markets] =>
[excluded_geo_locations] => Array
(
[countries] => Array
(
)
)
[exclusions] =>
[user_adclusters] =>
[interests] =>
[user_os] =>
[user_device] =>
[wireless_carrier] =>
[page_types] => Array
(
[0] => desktopfeed
[1] => mobilefeed
[2] => mobileexternal
[3] => rightcolumn
)
[connections] =>
[excluded_connections] =>
[family_statuses] =>
[friends_of_connections] =>
[flexible_spec] => Array
(
[0] => Array
(
[interests] => Array
(
[0] => Array
(
[id] => 6003277229371
)
)
[behaviors] => Array
(
[0] => Array
(
[id] => 6017447625983
)
)
)
)
[behaviors] =>
[relationship_statuses] =>
[interested_in] =>
[life_events] =>
[location_types] =>
[politics] =>
[markets] =>
[industries] =>
[income] =>
[net_worth] =>
[home_type] =>
[home_ownership] =>
[home_value] =>
[ethnic_affinity] =>
[generation] =>
[household_composition] =>
[moms] =>
[office_type] =>
[education_schools] =>
[education_statuses] =>
[college_years] =>
[education_majors] =>
[work_employers] =>
[work_positions] =>
[locales] =>
[zips] =>
[custom_audiences] =>
[custom_locations] =>
[excluded_custom_audiences] =>
[dynamic_audience_ids] =>
[product_audience_specs] =>
[excluded_product_audience_specs] =>
)
)
[promoted_object] =>
[adlabels] =>
[product_ad_behavior] =>
[execution_options] =>
[configured_status] =>
[effective_status] =>
)
I shortened the targeting for simplicity sake, but there's over 100 postal codes being targetd.
The solution here is that lifetime_budget is denoted in cents, so $64 should be 6400.
You may check if the budget you set is not less of required.
Perform this check at the endpoint:
https://graph.facebook.com/v2.12/act_{ads_account_id}/minimum_budgets
With headers:
Authorization: Bearer {your token with 'ads_management' rights to this account}
Returns:
{
"data": [
{
"currency": "AED",
"min_daily_budget_imp": 300,
"min_daily_budget_video_views": 300,
"min_daily_budget_high_freq": 750,
"min_daily_budget_low_freq": 6000
},
{
"currency": "ARS",
"min_daily_budget_imp": 400,
"min_daily_budget_video_views": 400,
"min_daily_budget_high_freq": 1000,
"min_daily_budget_low_freq": 8000
}
]
}
PS. I see, that my response is 2 years late, but someone may find it useful.

How to read youtube data api v3 response in php

I have following code:
$yt_profiles = $youtube->channels->listChannels('brandingSettings', array(
'mine' => 'true',
));
That returns the following output:
Google_Service_YouTube_ChannelListResponse Object
(
[collection_key:protected] => items
[etag] => "WFPuK6TsnblcGPcnMex79s42ynQ/sTnuE1bHO-tokx_mFFDt1ybN90g"
[eventId] =>
[itemsType:protected] => Google_Service_YouTube_Channel
[itemsDataType:protected] => array
[kind] => youtube#channelListResponse
[nextPageToken] =>
[pageInfoType:protected] => Google_Service_YouTube_PageInfo
[pageInfoDataType:protected] =>
[prevPageToken] =>
[tokenPaginationType:protected] => Google_Service_YouTube_TokenPagination
[tokenPaginationDataType:protected] =>
[visitorId] =>
[modelData:protected] => Array
(
[pageInfo] => Array
(
[totalResults] => 1
[resultsPerPage] => 1
)
[items] => Array
(
[0] => Array
(
[kind] => youtube#channel
[etag] => "WFPuK6TsnblcGPcnMex79s42ynQ/ecOcHFmWyWQ7ToCD7-B1L36b4L4"
[id] => UCQO6uXy5maTpYvSa_yM--Bw
[brandingSettings] => Array
(
[channel] => Array
(
[title] => Vasim Padhiyar
[showRelatedChannels] => 1
[featuredChannelsTitle] => Featured Channels
[featuredChannelsUrls] => Array
(
[0] => UCw-TnDmYDQyjnZ5qpVWUsSA
)
[profileColor] => #000000
)
[image] => Array
(
[bannerImageUrl] => http://s.ytimg.com/yts/img/channels/c4/default_banner-vfl7DRgTn.png
)
[hints] => Array
(
[0] => Array
(
[property] => channel.featured_tab.template.string
[value] => Everything
)
[1] => Array
(
[property] => channel.banner.image_height.int
[value] => 0
)
[2] => Array
(
[property] => channel.modules.show_comments.bool
[value] => True
)
)
)
)
)
)
[processed:protected] => Array
(
)
)
I want to loop through modelData:protected variable to get the list of channels and its items data. Its json object so $yt_profiles->modelData:protected not working while accessing. Please help me to solve this issue.
Thanks in advance
You can reach it as in an array:
print_r ($yt_profiles['modelData']);
Your request:
$yt_profiles = $youtube->channels->listChannels('brandingSettings', array(
'mine' => 'true',
));
To acces to values Channel title for example:
$titleChannel = $yt_profiles["items"][0]["brandingSettings"]["channel"]["title"];
To acces to values bannerImageUrl for example:
$banner = $yt_profiles["items"][0]["brandingSettings"]["image"]["bannerImageUrl"];
Does this help you?
$yt_profiles = $youtube->channels->listChannels('id, brandingSettings', array('mine' => 'true',));
foreach ($yt_profiles['modelData']['items'] as $searchResult) {
switch ($searchResult['kind']) {
case 'youtube#channel':
$channels[]= array('id'=> $searchResult['id'],
'brandingSettings'=> $searchResult['brandingSettings']);
break;
}
}