Related
Laravel custom pagination page 2 result return as object not array.
This is my code of custom pagination
function custom_paginate($data)
{
//Get current page form url e.g. &page=6
$currentPage = LengthAwarePaginator::resolveCurrentPage();
//Create a new Laravel collection from the array data
$collection = new Collection($data);
//Define how many items we want to be visible in each page
$per_page = (int) per_page();
//Slice the collection to get the items to display in current page
$currentPageResults = $collection->slice(($currentPage - 1) * $per_page, $per_page)->all();
//Create our paginator and add it to the data array
$data['results'] = new LengthAwarePaginator($currentPageResults, count($collection), $per_page);
//Set base url for pagination links to follow e.g custom/url?page=6
return $data['results']->setPath(request()->url());
}
when i am at page 1 data is coming as array but in same code if i passed page=2result is coming as object.
Expected result
{
"current_page": 2,
"data": [
{
"_id": 34,
"state": "Andaman & Nicobar Islands",
"post_count": 8,
"totalPhotos": 0,
"totalVideos": 1,
"totalAudios": 0
},
{
"_id": 28,
"state": "Andhra Pradesh",
"post_count": 888,
"totalPhotos": 0,
"totalVideos": 111,
"totalAudios": 0
},
{
"_id": 12,
"state": "Arunachal Pradesh",
"post_count": 200,
"totalPhotos": 0,
"totalVideos": 25,
"totalAudios": 0
},
{
"_id": 18,
"state": "Assam",
"post_count": 464,
"totalPhotos": 0,
"totalVideos": 58,
"totalAudios": 0
},
{
"_id": 10,
"state": "Bihar",
"post_count": 1072,
"totalPhotos": 0,
"totalVideos": 134,
"totalAudios": 0
}
],
"first_page_url": "http://swachh-manch-data.git/insight/posts?page=1",
"from": 6,
"last_page": 8,
"last_page_url": "http://swachh-manch-data.git/insight/posts?page=8",
"next_page_url": "http://swachh-manch-data.git/insight/posts?page=3",
"path": "http://swachh-manch-data.git/insight/posts",
"per_page": 5,
"prev_page_url": "http://swachh-manch-data.git/insight/posts?page=1",
"to": 10,
"total": 36
}
but getting data as object on page 2 (Actual result)
{
"current_page": 2,
"data": {
"5": {
"_id": 4,
"state": "Chandigarh",
"post_count": 8,
"totalPhotos": 0,
"totalVideos": 1,
"totalAudios": 0
},
"6": {
"_id": 22,
"state": "Chhattisgarh",
"post_count": 1336,
"totalPhotos": 0,
"totalVideos": 167,
"totalAudios": 0
},
"7": {
"_id": 26,
"state": "Dadra & Nagar Haveli",
"post_count": 8,
"totalPhotos": 0,
"totalVideos": 1,
"totalAudios": 0
},
"8": {
"_id": 25,
"state": "Daman & Diu",
"post_count": 16,
"totalPhotos": 0,
"totalVideos": 2,
"totalAudios": 0
},
"9": {
"_id": 7,
"state": "Delhi",
"post_count": 40,
"totalPhotos": 0,
"totalVideos": 5,
"totalAudios": 0
}
},
"first_page_url": "http://swachh-manch-data.git/insight/posts?page=1",
"from": 6,
"last_page": 8,
"last_page_url": "http://swachh-manch-data.git/insight/posts?page=8",
"next_page_url": "http://swachh-manch-data.git/insight/posts?page=3",
"path": "http://swachh-manch-data.git/insight/posts",
"per_page": 5,
"prev_page_url": "http://swachh-manch-data.git/insight/posts?page=1",
"to": 10,
"total": 36
}
i am not sure but the problem is in $currentPageResults = $collection->slice(($currentPage - 1) * $per_page, $per_page)->all(); this line.
Thanks in advance. :)
Change
$currentPageResults = $collection->slice(($currentPage - 1) * $per_page, $per_page)->all();
to
$currentPageResults = $collection->slice(($currentPage - 1) * $per_page, $per_page)->values();
for more info read this.
I'm trying to do some data transformation through Laravel collection in my application for graphs. I want to create labels and datasets
I'm having a data something like this:
[
{
"id": 1,
"company_id": 1,
"year": 25,
"turnover": "3449",
"profit": "3201",
"turnover_range": 25,
"financial_year": {
"id": 25,
"year": "2024-25"
}
},
{
"id": 2,
"company_id": 1,
"year": 33,
"turnover": "5616",
"profit": "5905",
"turnover_range": 25,
"financial_year": {
"id": 33,
"year": "2032-33"
}
},
{
"id": 3,
"company_id": 1,
"year": 1,
"turnover": "4309",
"profit": "8563",
"turnover_range": 175,
"financial_year": {
"id": 1,
"year": "2000-01"
}
},
{
"id": 4,
"company_id": 1,
"year": 14,
"turnover": "5936",
"profit": "8605",
"turnover_range": 25,
"financial_year": {
"id": 14,
"year": "2013-14"
}
},
{
"id": 5,
"company_id": 1,
"year": 29,
"turnover": "7156",
"profit": "3844",
"turnover_range": 75,
"financial_year": {
"id": 29,
"year": "2028-29"
}
},
{
"id": 6,
"company_id": 1,
"year": 6,
"turnover": "5868",
"profit": "633",
"turnover_range": 75,
"financial_year": {
"id": 6,
"year": "2005-06"
}
},
{
"id": 7,
"company_id": 1,
"year": 25,
"turnover": "5809",
"profit": "6831",
"turnover_range": 575,
"financial_year": {
"id": 25,
"year": "2024-25"
}
},
{
"id": 8,
"company_id": 1,
"year": 12,
"turnover": "1",
"profit": "1976",
"turnover_range": 25,
"financial_year": {
"id": 12,
"year": "2011-12"
}
},
{
"id": 9,
"company_id": 1,
"year": 30,
"turnover": "680",
"profit": "1222",
"turnover_range": 25,
"financial_year": {
"id": 30,
"year": "2029-30"
}
},
{
"id": 10,
"company_id": 1,
"year": 26,
"turnover": "8197",
"profit": "3687",
"turnover_range": 25,
"financial_year": {
"id": 26,
"year": "2025-26"
}
}
]
Which is coming from eloquent collection of my model:
$fRA = FinancialAndRisk::whereHas('company', function($q) use($request){
$q->where('slug', $request->slug);
})
->with('financialYear')
->get();
I want to pluck out all the year inside financial_year as labels so i tried:
$labels = $fRA->pluck('financial_year.year');
it is showing null.
Again I tried
$labels= $fRA->map(function ($item){
$item->fin_year = $item->financial_year['year'];
return $item;
})->pluck('fin_year');
Even if I do transform I am getting the same null result,
Any ideas appreciated. Thanks
Edit:
Data format to be something like this:
labels = ['2000-01','2032-33','2024-25','2005-06'];
You should just be able to do something like:
$labels = $fRA->map(function ($item) {
return $item->financial_year->year;
})->unique();
Obviously, remove unique() if you want to include the duplicates (if there are any).
Alternatively, if you have the hasMany relationship set up in your FinancialYear model and you don't need $fRA after this you could just do:
$labels = FinancialYear::whereHas('FinancialAndRisk.company', function ($query) use($request) {
$query->where('slug', $request->slug);
})->pluck('year');
I am trying to get the order list using the below url,
GET METHOD - http://magento.local/index.php/rest/V1/orders?searchCriteria
Header: Authorization: Bearer TOKEN(Customer Token)
But its giving the following response,
{
"message": "Consumer is not authorized to access %resources",
"parameters": {
"resources": "Magento_Sales::sales"
}
}
what needs to be done to get the order list using customer token?
Unfortunately it's not implemented in Magento_Sales::sales yet, but you can extend your own API. follow the following issue:
https://github.com/magento/magento2/issues/3552
For the get Customer Order history use searchCriteria and passed customer_email id.
Follow below Magento 2 API to get the customer order history.
Request URL:
https://magento.com/rest/V1/orders?searchCriteria[filter_groups][0][filters][0][field]=customer_email&searchCriteria[filter_groups][0][filters][0][value]=test#gmail.com
Method: GET
Response:
{
"items": [
{
"base_currency_code": "KWD",
"base_discount_amount": 0,
"base_grand_total": 40,
"base_discount_tax_compensation_amount": 0,
"base_shipping_amount": 10,
"base_shipping_discount_amount": 0,
"base_shipping_discount_tax_compensation_amnt": 0,
"base_shipping_incl_tax": 10,
"base_shipping_tax_amount": 0,
"base_subtotal": 30,
"base_subtotal_incl_tax": 30,
"base_tax_amount": 0,
"base_total_due": 40,
"base_to_global_rate": 1,
"base_to_order_rate": 1,
"billing_address_id": 250,
"created_at": "2019-08-14 11:26:48",
"customer_email": "test#gmail.com",
"customer_firstname": "Test",
"customer_group_id": 1,
"customer_id": 51,
"customer_is_guest": 0,
"customer_lastname": "Customer",
"customer_note_notify": 1,
"discount_amount": 0,
"email_sent": 1,
"entity_id": 125,
"global_currency_code": "KWD",
"grand_total": 40,
"discount_tax_compensation_amount": 0,
"increment_id": "000000119",
"is_virtual": 0,
"order_currency_code": "KWD",
"protect_code": "9a7b171724410d42aec193ba5206901e",
"quote_id": 398,
"remote_ip": "202.131.115.180",
"shipping_amount": 10,
"shipping_description": "Flat Rate - Fixed",
"shipping_discount_amount": 0,
"shipping_discount_tax_compensation_amount": 0,
"shipping_incl_tax": 10,
"shipping_tax_amount": 0,
"state": "new",
"status": "pending",
"store_currency_code": "KWD",
"store_id": 1,
"store_name": "Default Store",
"store_to_base_rate": 0,
"store_to_order_rate": 0,
"subtotal": 30,
"subtotal_incl_tax": 30,
"tax_amount": 0,
"total_due": 40,
"total_item_count": 1,
"total_qty_ordered": 2,
"updated_at": "2019-08-14 11:26:49",
"weight": 0,
"items": [
{
"amount_refunded": 0,
"base_amount_refunded": 0,
"base_cost": 8.5,
"base_discount_amount": 0,
"base_discount_invoiced": 0,
"base_discount_tax_compensation_amount": 0,
"base_original_price": 15,
"base_price": 15,
"base_price_incl_tax": 15,
"base_row_invoiced": 0,
"base_row_total": 30,
"base_row_total_incl_tax": 30,
"base_tax_amount": 0,
"base_tax_invoiced": 0,
"created_at": "2019-08-14 11:26:48",
"discount_amount": 0,
"discount_invoiced": 0,
"discount_percent": 0,
"free_shipping": 0,
"discount_tax_compensation_amount": 0,
"is_qty_decimal": 0,
"is_virtual": 0,
"item_id": 341,
"name": "DIAMOND GLITTER GRAY",
"no_discount": 0,
"order_id": 125,
"original_price": 15,
"price": 15,
"price_incl_tax": 15,
"product_id": 228,
"product_type": "simple",
"qty_canceled": 0,
"qty_invoiced": 0,
"qty_ordered": 2,
"qty_refunded": 0,
"qty_shipped": 0,
"quote_item_id": 1281,
"row_invoiced": 0,
"row_total": 30,
"row_total_incl_tax": 30,
"row_weight": 0,
"sku": "CLBELGLG0175DCMO",
"store_id": 1,
"tax_amount": 0,
"tax_invoiced": 0,
"tax_percent": 0,
"updated_at": "2019-08-14 11:26:48"
}
],
"billing_address": {
"address_type": "billing",
"city": "California",
"company": "Company",
"country_id": "US",
"email": "test#gmail.com",
"entity_id": 250,
"firstname": "john",
"lastname": "harrison",
"parent_id": 125,
"postcode": "12345",
"region": "New York",
"region_code": "NY",
"region_id": 43,
"street": [
"Street Address"
],
"telephone": "2313131312"
},
"payment": {
"account_status": null,
"additional_information": [
"Check / Money order"
],
"amount_ordered": 40,
"base_amount_ordered": 40,
"base_shipping_amount": 10,
"cc_exp_year": "0",
"cc_last4": null,
"cc_ss_start_month": "0",
"cc_ss_start_year": "0",
"entity_id": 125,
"method": "checkmo",
"parent_id": 125,
"shipping_amount": 10
},
"status_histories": [],
"extension_attributes": {
"shipping_assignments": [
{
"shipping": {
"address": {
"address_type": "shipping",
"city": "California",
"company": "Company",
"country_id": "US",
"email": "test#gmail.com",
"entity_id": 249,
"firstname": "john",
"lastname": "harrison",
"parent_id": 125,
"postcode": "12345",
"region": "New York",
"region_code": "NY",
"region_id": 43,
"street": [
"Street Address"
],
"telephone": "2313131312"
},
"method": "flatrate_flatrate",
"total": {
"base_shipping_amount": 10,
"base_shipping_discount_amount": 0,
"base_shipping_discount_tax_compensation_amnt": 0,
"base_shipping_incl_tax": 10,
"base_shipping_tax_amount": 0,
"shipping_amount": 10,
"shipping_discount_amount": 0,
"shipping_discount_tax_compensation_amount": 0,
"shipping_incl_tax": 10,
"shipping_tax_amount": 0
}
},
"items": [
{
"amount_refunded": 0,
"base_amount_refunded": 0,
"base_cost": 8.5,
"base_discount_amount": 0,
"base_discount_invoiced": 0,
"base_discount_tax_compensation_amount": 0,
"base_original_price": 15,
"base_price": 15,
"base_price_incl_tax": 15,
"base_row_invoiced": 0,
"base_row_total": 30,
"base_row_total_incl_tax": 30,
"base_tax_amount": 0,
"base_tax_invoiced": 0,
"created_at": "2019-08-14 11:26:48",
"discount_amount": 0,
"discount_invoiced": 0,
"discount_percent": 0,
"free_shipping": 0,
"discount_tax_compensation_amount": 0,
"is_qty_decimal": 0,
"is_virtual": 0,
"item_id": 341,
"name": "BELLA DIAMOND GLITTER GRAY 0175",
"no_discount": 0,
"order_id": 125,
"original_price": 15,
"price": 15,
"price_incl_tax": 15,
"product_id": 228,
"product_type": "simple",
"qty_canceled": 0,
"qty_invoiced": 0,
"qty_ordered": 2,
"qty_refunded": 0,
"qty_shipped": 0,
"quote_item_id": 1281,
"row_invoiced": 0,
"row_total": 30,
"row_total_incl_tax": 30,
"row_weight": 0,
"sku": "CLBELGLG0175DCMO",
"store_id": 1,
"tax_amount": 0,
"tax_invoiced": 0,
"tax_percent": 0,
"updated_at": "2019-08-14 11:26:48"
}
]
}
],
"rewards_discount": 0,
"rewards_spend": 0,
"rewards_earn": 950
}
},
{
"applied_rule_ids": "4,11",
"base_currency_code": "KWD",
"base_discount_amount": -15,
"base_grand_total": 165,
"base_discount_tax_compensation_amount": 0,
"base_shipping_amount": 45,
"base_shipping_discount_amount": 0,
"base_shipping_discount_tax_compensation_amnt": 0,
"base_shipping_incl_tax": 45,
"base_shipping_tax_amount": 0,
"base_subtotal": 135,
"base_subtotal_incl_tax": 135,
"base_tax_amount": 0,
"base_total_due": 165,
"base_to_global_rate": 1,
"base_to_order_rate": 1,
"billing_address_id": 268,
"created_at": "2019-09-24 13:16:32",
"customer_email": "test#gmail.com",
"customer_firstname": "Test",
"customer_group_id": 1,
"customer_id": 51,
"customer_is_guest": 0,
"customer_lastname": "Customer",
"customer_note_notify": 1,
"discount_amount": -15,
"email_sent": 1,
"entity_id": 134,
"global_currency_code": "KWD",
"grand_total": 165,
"discount_tax_compensation_amount": 0,
"increment_id": "000000128",
"is_virtual": 0,
"order_currency_code": "KWD",
"protect_code": "1deccd785628b2df682d9156db732fc0",
"quote_id": 408,
"shipping_amount": 45,
"shipping_description": "Flat Rate - Fixed",
"shipping_discount_amount": 0,
"shipping_discount_tax_compensation_amount": 0,
"shipping_incl_tax": 45,
"shipping_tax_amount": 0,
"state": "new",
"status": "pending",
"store_currency_code": "KWD",
"store_id": 1,
"store_name": "Default Store",
"store_to_base_rate": 0,
"store_to_order_rate": 0,
"subtotal": 135,
"subtotal_incl_tax": 135,
"tax_amount": 0,
"total_due": 165,
"total_item_count": 1,
"total_qty_ordered": 9,
"updated_at": "2019-09-24 13:16:33",
"weight": 0,
"items": [
{
"amount_refunded": 0,
"applied_rule_ids": "4,11",
"base_amount_refunded": 0,
"base_cost": 8.5,
"base_discount_amount": 15,
"base_discount_invoiced": 0,
"base_discount_tax_compensation_amount": 0,
"base_original_price": 15,
"base_price": 15,
"base_price_incl_tax": 15,
"base_row_invoiced": 0,
"base_row_total": 135,
"base_row_total_incl_tax": 135,
"base_tax_amount": 0,
"base_tax_invoiced": 0,
"created_at": "2019-09-24 13:16:32",
"discount_amount": 15,
"discount_invoiced": 0,
"discount_percent": 0,
"free_shipping": 0,
"discount_tax_compensation_amount": 0,
"is_qty_decimal": 0,
"is_virtual": 0,
"item_id": 351,
"name": "BELLA DIAMOND GLITTER GRAY 0175",
"no_discount": 0,
"order_id": 134,
"original_price": 15,
"price": 15,
"price_incl_tax": 15,
"product_id": 228,
"product_type": "simple",
"qty_canceled": 0,
"qty_invoiced": 0,
"qty_ordered": 9,
"qty_refunded": 0,
"qty_shipped": 0,
"quote_item_id": 1378,
"row_invoiced": 0,
"row_total": 135,
"row_total_incl_tax": 135,
"row_weight": 0,
"sku": "CLBELGLG0175DCMO",
"store_id": 1,
"tax_amount": 0,
"tax_invoiced": 0,
"tax_percent": 0,
"updated_at": "2019-09-24 13:16:32"
}
],
"billing_address": {
"address_type": "billing",
"city": "California",
"company": "Company",
"country_id": "US",
"email": "test#gmail.com",
"entity_id": 268,
"firstname": "john",
"lastname": "harrison",
"parent_id": 134,
"postcode": "12345",
"region": "New York",
"region_code": "NY",
"region_id": 43,
"street": [
"Street Address"
],
"telephone": "2313131312"
},
"payment": {
"account_status": null,
"additional_information": [
"Check / Money order"
],
"amount_ordered": 165,
"base_amount_ordered": 165,
"base_shipping_amount": 45,
"cc_exp_year": "0",
"cc_last4": null,
"cc_ss_start_month": "0",
"cc_ss_start_year": "0",
"entity_id": 134,
"method": "checkmo",
"parent_id": 134,
"shipping_amount": 45
},
"status_histories": [],
"extension_attributes": {
"shipping_assignments": [
{
"shipping": {
"address": {
"address_type": "shipping",
"city": "California",
"company": "Company",
"country_id": "US",
"email": "test#gmail.com",
"entity_id": 267,
"firstname": "john",
"lastname": "harrison",
"parent_id": 134,
"postcode": "12345",
"region": "New York",
"region_code": "NY",
"region_id": 43,
"street": [
"Street Address"
],
"telephone": "2313131312"
},
"method": "flatrate_flatrate",
"total": {
"base_shipping_amount": 45,
"base_shipping_discount_amount": 0,
"base_shipping_discount_tax_compensation_amnt": 0,
"base_shipping_incl_tax": 45,
"base_shipping_tax_amount": 0,
"shipping_amount": 45,
"shipping_discount_amount": 0,
"shipping_discount_tax_compensation_amount": 0,
"shipping_incl_tax": 45,
"shipping_tax_amount": 0
}
},
"items": [
{
"amount_refunded": 0,
"applied_rule_ids": "4,11",
"base_amount_refunded": 0,
"base_cost": 8.5,
"base_discount_amount": 15,
"base_discount_invoiced": 0,
"base_discount_tax_compensation_amount": 0,
"base_original_price": 15,
"base_price": 15,
"base_price_incl_tax": 15,
"base_row_invoiced": 0,
"base_row_total": 135,
"base_row_total_incl_tax": 135,
"base_tax_amount": 0,
"base_tax_invoiced": 0,
"created_at": "2019-09-24 13:16:32",
"discount_amount": 15,
"discount_invoiced": 0,
"discount_percent": 0,
"free_shipping": 0,
"discount_tax_compensation_amount": 0,
"is_qty_decimal": 0,
"is_virtual": 0,
"item_id": 351,
"name": "BELLA DIAMOND GLITTER GRAY 0175",
"no_discount": 0,
"order_id": 134,
"original_price": 15,
"price": 15,
"price_incl_tax": 15,
"product_id": 228,
"product_type": "simple",
"qty_canceled": 0,
"qty_invoiced": 0,
"qty_ordered": 9,
"qty_refunded": 0,
"qty_shipped": 0,
"quote_item_id": 1378,
"row_invoiced": 0,
"row_total": 135,
"row_total_incl_tax": 135,
"row_weight": 0,
"sku": "CLBELGLG0175DCMO",
"store_id": 1,
"tax_amount": 0,
"tax_invoiced": 0,
"tax_percent": 0,
"updated_at": "2019-09-24 13:16:32"
}
]
}
],
"rewards_discount": 0,
"rewards_spend": 0,
"rewards_earn": 3770
}
}
],
"search_criteria": {
"filter_groups": [
{
"filters": [
{
"field": "customer_email",
"value": "test#gmail.com",
"condition_type": "eq"
}
]
}
]
},
"total_count": 2
}
My json data
{
"total": 533489,
"page": 1,
"pagesize": 30,
"questions": [
{
"tags": [
"php",
"html",
"forms"
],
"answer_count": 6,
"favorite_count": 0,
"question_timeline_url": "/questions/22075370/timeline",
"question_comments_url": "/questions/22075370/comments",
"question_answers_url": "/questions/22075370/answers",
"question_id": 22075370,
"owner": {
"user_id": 3343981,
"user_type": "registered",
"display_name": "user3343981",
"reputation": 3,
"email_hash": "55d0eb4577a0ba9f9e428d445431b595"
},
"creation_date": 1393520772,
"last_activity_date": 1393522799,
"up_vote_count": 0,
"down_vote_count": 0,
"view_count": 48,
"score": 0,
"community_owned": false,
"title": "Issues with my form"
},
{
"tags": [
"php",
"arrays"
],
"answer_count": 0,
"favorite_count": 0,
"question_timeline_url": "/questions/22076141/timeline",
"question_comments_url": "/questions/22076141/comments",
"question_answers_url": "/questions/22076141/answers",
"question_id": 22076141,
"owner": {
"user_id": 1479092,
"user_type": "registered",
"display_name": "Waldermort",
"reputation": 470,
"email_hash": "a00b970322ae60986ca4ed7629c7389b"
},
"creation_date": 1393522754,
"last_activity_date": 1393522754,
"up_vote_count": 0,
"down_vote_count": 0,
"view_count": 12,
"score": 0,
"community_owned": false,
"title": "How to find the first free key in an array"
},
{
"tags": [
"php",
"codeigniter",
"postgresql"
],
"answer_count": 0,
"favorite_count": 0,
"question_timeline_url": "/questions/22076140/timeline",
"question_comments_url": "/questions/22076140/comments",
"question_answers_url": "/questions/22076140/answers",
"question_id": 22076140,
"owner": {
"user_id": 3220020,
"user_type": "registered",
"display_name": "Kino",
"reputation": 18,
"email_hash": "839332924b8b9e3fdbc1465690378aa2"
},
"creation_date": 1393522752,
"last_activity_date": 1393522752,
"up_vote_count": 0,
"down_vote_count": 0,
"view_count": 3,
"score": 0,
"community_owned": false,
"title": "multiply 2 values from different table using codeigniter and postgresql foreach()"
},
{
"tags": [
"php"
],
"answer_count": 1,
"favorite_count": 0,
"question_timeline_url": "/questions/22076037/timeline",
"question_comments_url": "/questions/22076037/comments",
"question_answers_url": "/questions/22076037/answers",
"question_id": 22076037,
"owner": {
"user_id": 2719411,
"user_type": "registered",
"display_name": "Xander",
"reputation": 12,
"email_hash": "66a15843818fbcbc6aa01c19ec62aed0"
},
"creation_date": 1393522498,
"last_activity_date": 1393522735,
"up_vote_count": 0,
"down_vote_count": 0,
"view_count": 24,
"score": 0,
"community_owned": false,
"title": "Hide div based on time - PHP"
},
{
"tags": [
"php",
".htaccess",
"ping",
"password-protection"
],
"answer_count": 0,
"favorite_count": 0,
"question_timeline_url": "/questions/22076119/timeline",
"question_comments_url": "/questions/22076119/comments",
"question_answers_url": "/questions/22076119/answers",
"question_id": 22076119,
"owner": {
"user_id": 3361650,
"user_type": "registered",
"display_name": "user3361650",
"reputation": 1,
"email_hash": "84fd66f3c92515f9d2a45a2ca507a0ab"
},
"creation_date": 1393522695,
"last_activity_date": 1393522695,
"up_vote_count": 0,
"down_vote_count": 0,
"view_count": 8,
"score": 0,
"community_owned": false,
"title": "How to check website is online if it is password protected"
},
{
"tags": [
"php",
"string",
"random"
],
"answer_count": 2,
"favorite_count": 0,
"question_timeline_url": "/questions/22075958/timeline",
"question_comments_url": "/questions/22075958/comments",
"question_answers_url": "/questions/22075958/answers",
"question_id": 22075958,
"owner": {
"user_id": 1573630,
"user_type": "registered",
"display_name": "Michal S",
"reputation": 157,
"email_hash": "05e9ad26aa0851931b7cca5f130ac081"
},
"creation_date": 1393522296,
"last_edit_date": 1393522474,
"last_activity_date": 1393522685,
"up_vote_count": 1,
"down_vote_count": 0,
"view_count": 24,
"score": 1,
"community_owned": false,
"title": "PHP - How to select random tag in the string"
},
{
"tags": [
"php",
"symfony2",
"symfony-forms"
],
"answer_count": 1,
"accepted_answer_id": 22076109,
"favorite_count": 0,
"question_timeline_url": "/questions/22075054/timeline",
"question_comments_url": "/questions/22075054/comments",
"question_answers_url": "/questions/22075054/answers",
"question_id": 22075054,
"owner": {
"user_id": 245552,
"user_type": "registered",
"display_name": "Matthieu Napoli",
"reputation": 7586,
"email_hash": "48906ce482893497d2d7e017cd2f4352"
},
"creation_date": 1393519990,
"last_activity_date": 1393522680,
"up_vote_count": 0,
"down_vote_count": 0,
"view_count": 9,
"score": 0,
"community_owned": false,
"title": "Symfony form: customize the setter that is called"
},
{
"tags": [
"php",
"wordpress",
"sorting"
],
"answer_count": 0,
"favorite_count": 0,
"question_timeline_url": "/questions/22076089/timeline",
"question_comments_url": "/questions/22076089/comments",
"question_answers_url": "/questions/22076089/answers",
"question_id": 22076089,
"owner": {
"user_id": 2279387,
"user_type": "registered",
"display_name": "Tomas Kleinotas",
"reputation": 7,
"email_hash": "6ba9fc650c619efae62691c8456ca76f"
},
"creation_date": 1393522645,
"last_activity_date": 1393522645,
"up_vote_count": 0,
"down_vote_count": 0,
"view_count": 3,
"score": 0,
"community_owned": false,
"title": "How to sort category posts by meta_value if there are empty fields?"
},
{
"tags": [
"php",
"mysql",
"pdf",
"embed",
"blob"
],
"answer_count": 1,
"favorite_count": 0,
"question_timeline_url": "/questions/22075847/timeline",
"question_comments_url": "/questions/22075847/comments",
"question_answers_url": "/questions/22075847/answers",
"question_id": 22075847,
"owner": {
"user_id": 3346480,
"user_type": "registered",
"display_name": "Richard",
"reputation": 1,
"email_hash": "40e5ef3a529b8b66ec994c2b6a1d1555"
},
"creation_date": 1393522007,
"last_activity_date": 1393522615,
"up_vote_count": 0,
"down_vote_count": 0,
"view_count": 3,
"score": 0,
"community_owned": false,
"title": "embed pdf from blob to html/php page"
},
{
"tags": [
"php"
],
"answer_count": 2,
"favorite_count": 0,
"question_timeline_url": "/questions/22075599/timeline",
"question_comments_url": "/questions/22075599/comments",
"question_answers_url": "/questions/22075599/answers",
"question_id": 22075599,
"owner": {
"user_id": 3361419,
"user_type": "registered",
"display_name": "Eduardo",
"reputation": 1,
"email_hash": "e3561abf3d1b9969686df7113a4d82f6"
},
"creation_date": 1393521373,
"last_activity_date": 1393522615,
"up_vote_count": 0,
"down_vote_count": 6,
"view_count": 16,
"score": -6,
"community_owned": false,
"title": "Parse syntax error, unexpected end of file in C:\\xampp\\htdocs\\Pap\\create.php on line 292"
},
{
"tags": [
"php",
"forms",
"checkbox",
"tcpdf"
{
"tags": [
"php",
"composer-php",
"directory-structure",
"laravel-4.1"
],
"answer_count": 0,
"favorite_count": 0,
"question_timeline_url": "/questions/22075957/timeline",
"question_comments_url": "/questions/22075957/comments",
"question_answers_url": "/questions/22075957/answers",
"question_id": 22075957,
"owner": {
"user_id": 1202367,
"user_type": "registered",
"display_name": "Claudio Ludovico Panetta",
"reputation": 393,
"email_hash": "2dca89fe809118d3a93d5a51e2cd28bd"
},
"creation_date": 1393522295,
"last_activity_date": 1393522295,
"up_vote_count": 0,
"down_vote_count": 0,
"view_count": 5,
"score": 0,
"community_owned": false,
"title": "Centralize vendor folder in Laravel 4.1.x"
},
{
"tags": [
"php",
"sms"
],
"answer_count": 0,
"favorite_count": 0,
"question_timeline_url": "/questions/22075948/timeline",
"question_comments_url": "/questions/22075948/comments",
"question_answers_url": "/questions/22075948/answers",
"question_id": 22075948,
"owner": {
"user_id": 3333903,
"user_type": "registered",
"display_name": "ArpanTechBuddy",
"reputation": 1,
"email_hash": "2abb3673c9cca94de81942f3b0b0488b"
},
"creation_date": 1393522276,
"last_activity_date": 1393522276,
"up_vote_count": 0,
"down_vote_count": 3,
"view_count": 12,
"score": -3,
"community_owned": false,
"title": "SMS from PHP to any number for free"
},
{
"tags": [
"php",
"curl"
],
"answer_count": 4,
"favorite_count": 0,
"question_timeline_url": "/questions/22075803/timeline",
"question_comments_url": "/questions/22075803/comments",
"question_answers_url": "/questions/22075803/answers",
"question_id": 22075803,
"owner": {
"user_id": 1459253,
"user_type": "registered",
"display_name": "Siddesh Bhalke",
"reputation": 671,
"email_hash": "262597fd50cb34b6ddbc168b8f2d77a5"
},
"creation_date": 1393521922,
"last_activity_date": 1393522259,
"up_vote_count": 0,
"down_vote_count": 0,
"view_count": 9,
"score": 0,
"community_owned": false,
"title": "curl_init() has been disabled for security reasons"
},
{
"tags": [
"php",
"wordpress",
"rewrite"
],
"answer_count": 2,
"favorite_count": 0,
"question_timeline_url": "/questions/18602715/timeline",
"question_comments_url": "/questions/18602715/comments",
"question_answers_url": "/questions/18602715/answers",
"question_id": 18602715,
"owner": {
"user_id": 648938,
"user_type": "registered",
"display_name": "Scrooby",
"reputation": 2164,
"email_hash": "f280a3e68d054f94c2afa52c950a40b9"
},
"creation_date": 1378248631,
"last_edit_date": 1393521961,
"last_activity_date": 1393522236,
"up_vote_count": 0,
"down_vote_count": 0,
"view_count": 116,
"score": 0,
"community_owned": false,
"title": "Page Not Found in title of WordPress page on template_redirect using include()"
},
{
"tags": [
"php",
"mysql",
"database-design"
],
"answer_count": 1,
"favorite_count": 0,
"question_timeline_url": "/questions/22075748/timeline",
"question_comments_url": "/questions/22075748/comments",
"question_answers_url": "/questions/22075748/answers",
"question_id": 22075748,
"owner": {
"user_id": 741156,
"user_type": "registered",
"display_name": "Momen M El Zalabany",
"reputation": 957,
"email_hash": "6819dd0de162410dcccd7b1b03bb5def"
},
"creation_date": 1393521798,
"last_edit_date": 1393522196,
"last_activity_date": 1393522196,
"up_vote_count": 0,
"down_vote_count": 0,
"view_count": 14,
"score": 0,
"community_owned": false,
"title": "mysql design for employees working hours"
},
{
"tags": [
"php",
"logging",
"controller",
"event-handling",
"zend-framework2"
],
"answer_count": 0,
"favorite_count": 0,
"question_timeline_url": "/questions/22075903/timeline",
"question_comments_url": "/questions/22075903/comments",
"question_answers_url": "/questions/22075903/answers",
"question_id": 22075903,
"owner": {
"user_id": 928044,
"user_type": "registered",
"display_name": "Vincent Caggiari",
"reputation": 8,
"email_hash": "3779e0b7d9bebe76c674bd59fa7016e9"
},
"creation_date": 1393522170,
"last_activity_date": 1393522170,
"up_vote_count": 0,
"down_vote_count": 0,
"view_count": 4,
"score": 0,
"community_owned": false,
"title": "zend 2 event manager wildcard + keywords"
},
{
"tags": [
"php",
"wordpress"
],
"answer_count": 0,
"favorite_count": 0,
"question_timeline_url": "/questions/22075764/timeline",
"question_comments_url": "/questions/22075764/comments",
"question_answers_url": "/questions/22075764/answers",
"question_id": 22075764,
"owner": {
"user_id": 1469270,
"user_type": "registered",
"display_name": "tmyie",
"reputation": 515,
"email_hash": "c7522e105f49699af313a6aba52a66bc"
},
"creation_date": 1393521834,
"last_edit_date": 1393522153,
"last_activity_date": 1393522153,
"up_vote_count": 0,
"down_vote_count": 0,
"view_count": 17,
"score": 0,
"community_owned": false,
"title": "Loop through all posts, show attachment if there (WordPress)"
},
{
"tags": [
"php",
"api",
"paypal",
"express",
"checkout"
],
"answer_count": 0,
"favorite_count": 0,
"question_timeline_url": "/questions/22074086/timeline",
"question_comments_url": "/questions/22074086/comments",
"question_answers_url": "/questions/22074086/answers",
"question_id": 22074086,
"owner": {
"user_id": 3361211,
"user_type": "registered",
"display_name": "PmLvgn",
"reputation": 1,
"email_hash": "a4df4e1cb22b77c2e898d791c117a3a5"
},
"creation_date": 1393517599,
"last_edit_date": 1393522102,
"last_activity_date": 1393522102,
"up_vote_count": 0,
"down_vote_count": 0,
"view_count": 8,
"score": 0,
"community_owned": false,
"title": "PHP Paypal API ExpressCheckout, i don't know what i sold in history details"
},
{
"tags": [
"php",
"braintree"
],
"answer_count": 1,
"favorite_count": 0,
"question_timeline_url": "/questions/22056863/timeline",
"question_comments_url": "/questions/22056863/comments",
"question_answers_url": "/questions/22056863/answers",
"question_id": 22056863,
"owner": {
"user_id": 1233455,
"user_type": "registered",
"display_name": "JasonMortonNZ",
"reputation": 967,
"email_hash": "1d2bc25a4d7db82dd86c411afda88e8f"
},
"creation_date": 1393462513,
"last_activity_date": 1393522017,
"up_vote_count": 1,
"down_vote_count": 0,
"view_count": 12,
"score": 1,
"community_owned": false,
"title": "Braintree API in PHP success and currency issue"
},
{
"tags": [
"php"
],
"answer_count": 0,
"favorite_count": 0,
"question_timeline_url": "/questions/22075831/timeline",
"question_comments_url": "/questions/22075831/comments",
"question_answers_url": "/questions/22075831/answers",
"question_id": 22075831,
"owner": {
"user_id": 3282713,
"user_type": "registered",
"display_name": "user3282713",
"reputation": 1,
"email_hash": "0fdeb1c7e8da488a6556ccc8386d0249"
},
"creation_date": 1393521988,
"last_activity_date": 1393521988,
"up_vote_count": 0,
"down_vote_count": 0,
"view_count": 6,
"score": 0,
"community_owned": false,
"title": "updating multiple items through checkbox in php"
},
{
"tags": [
"php",
"html"
],
"answer_count": 0,
"favorite_count": 0,
"question_timeline_url": "/questions/22075634/timeline",
"question_comments_url": "/questions/22075634/comments",
"question_answers_url": "/questions/22075634/answers",
"question_id": 22075634,
"owner": {
"user_id": 2640557,
"user_type": "registered",
"display_name": "aveleon",
"reputation": 20,
"email_hash": "b20903bea6646401a4d88a7852ae6229"
},
"creation_date": 1393521474,
"last_edit_date": 1393521949,
"last_activity_date": 1393521949,
"up_vote_count": 1,
"down_vote_count": 1,
"view_count": 44,
"score": 0,
"community_owned": false,
"title": "PHP is not working and cannot find out why (creating dynamic content)"
},
{
"tags": [
"php",
"android",
"web-services",
"mobile",
"service"
],
"answer_count": 1,
"favorite_count": 1,
"closed_date": 1393520310,
"closed_reason": "primarily opinion-based",
"question_timeline_url": "/questions/22075094/timeline",
"question_comments_url": "/questions/22075094/comments",
"question_answers_url": "/questions/22075094/answers",
"question_id": 22075094,
"owner": {
"user_id": 2715065,
"user_type": "registered",
"display_name": "Warde",
"reputation": 285,
"email_hash": "f265910523dec1dc1e11bb02b4af79a5"
},
"creation_date": 1393520062,
"last_edit_date": 1393521803,
"last_activity_date": 1393521803,
"up_vote_count": 0,
"down_vote_count": 9,
"view_count": 35,
"score": -9,
"community_owned": false,
"title": "Need a service that sends the complete information of contacts to the server"
}
]
}
Getting below error when i try json_decode('abovedata'),
ERROR:
Catchable fatal error: Object of class stdClass could not be
converted to string in F:\xamp\htdocs\xampp\curl.php on line 12
How can i read each key values from above json data ?
Try this..
json_decode($data,true);
Your JSON is invalid, that is why the function is not processing it correctly.
"tags": [
"php",
"forms",
"checkbox",
"tcpdf"
Look at this section here, you never close the [] in "tags". I used this JSON validator
I have written a below code which generates a area graph for selected dates (to and from dates).
$(document).ready(function() {
var options = {
"series": [{
"showInLegend": false,
"color": "#D0D0D0",
"name": "Revenue",
"data": [0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]}],
"credits": {
"enabled": false
},
"chart": {
"renderTo": "highchart_id",
"defaultSeriesType": "area",
"shadow": true
},
"title": {
"text": null,
"align": "center",
"x": 0,
"y": 20
},
"xAxis": {
"type": "datetime",
"dateTimeLabelFormats": {
"month": "%e. %b",
"year": "%b"
},
"labels": {
"enabled": "false"
}
},
"legend": {
"enabled": true
},
"yAxis": {
"title": {
"text": ""
},
"labels": {
"enabled": true
}
},
"plotOptions": {
"area": {
"stacking": "normal",
"lineColor": "#3E3E3E",
"lineWidth": 3,
"marker": {
"lineWidth": "1",
"lineColor": "#3E3E3E",
"states": {
"hover": {
"enabled": true,
"radius": 1
}
}
}
},
"series": {
"pointStart": 1335823200000,
"pointInterval": 86400000
}
}
};
var chart = new Highcharts.Chart(options);
});
The interval of dates on x-axis is coming one day less. here the series value 2 is for 10 may whereas it is showing for 9 may in graph.
I am new to this highchart, can anybody advice the solution please and let me known if you need any more clarification on the problem.
Try adding this code before declaring the chart
Highcharts.setOptions({
time: {
useUTC: false
}
});
By default highchart used UTC times. By adding the code above it will use the time zone of the browser.