I'm having an error in my Laravel 8 app which uses yajra/laravel-datatables-oracle with server-side rendering, and I can't figure it out so far. What makes it frustating is the fact that this have been working just fine for the last couple of months, and suddenly I got a report about this error just this morning.
So I have a page which shows a table. The table itself is pretty large, with more than 25 columns shown, thousands of total records, and with some nested relationships as well. For this, I use the yajra/laravel-datatables-oracle package with ajax/server-side rendering as I mentioned above. The page has pagination option enabled, and is set to show 50 records by default. The page is functioning correctly when opened in its default condition.
However, an error will happen when user changes the table's page-length to "All". After checking the the route that handles the table's ajax rendering, turns out the error happened because the returned json is not a valid json. So instead of getting a valid json like these:
"data": [
{"id": 1, "name": "Foo"},
// ....
{"id": 999, "name": "Bar"}
]
I get:
"data": [
{"id": 1, "name": "Foo"},
// ....
{"id": 500,
]
// or...
"data": [
{"id": 1, "name": "Foo"},
// ....
{"id": 500, "name": "Ja
]
The point is that the returned response is incomplete, which makes it invalid as a json, which makes the datatables throws a json bad parsing error.
These are the things for you to know:
Remember, this thing have been working fine for the last couple of months.
Just like the example above, the json response (which is incomplete) is always changing everytime I refresh the url. Meaning that it's likely not related to "abnormal" record.
The error occurs only if the selected page-lenght pass a certain amount of number:
It's working when just being selected (up to) 180 items per page (each item has a total of >100 fields).
More than 180 and the error will occur. However, the incompleteness could be anywhere, not in the 181'th item. It could be in the 70th-ish, 90th-ish, etc. In fact, It never returns more than 100 records when the error occur.
I had thought that this might be caused by PHP's memory exhaustion. I tried to set the memory_limit of the PHP to -1 or 999999M, but nothing changes.
This is actually not just happening in one page, but many.
However, there are another pages, that's working totally fine without the error above. The size of the data that it has is roughly the same.
I really have no idea what's the cause of this. Is this because of the server's PHP config, the database (mysql), the ajax request, or what?
Please help. You're much appreciated.
Additional Info
This is one of the method's controller where the error appears.
use App\Models\Instansi;
use App\Models\InstrukturKelasPeriodeTahapan;
use App\Models\Tahapan;
use App\Models\Tahun;
use Illuminate\Http\Request;
use Yajra\DataTables\Facades\DataTables;
public function datatable(Request $request) {
// validate request etc...
$jadwals = InstrukturKelasPeriodeTahapan::query()
->withInstruktur()->withKelasPeriodeTahapan()
->withTarifInTahunAndPeriodeOf($tahun, $periode)
->withPphInTahunAndPeriodeOf($tahun, $periode)
->withCount([
'pamongDalamKelasPeriodeTahapan as jumlah_pamong_yg_mengajar'
])
->whereHasTahunOf($tahun)
->whereHasPeriodeOf($periode)
->whereHasTahapanOf(Tahapan::PPP);
if ($request->instansi) {
if ($request->instansi == Instansi::NON_FOO) {
$jadwals->whereHasInstansiOfNonFoo();
} else {
$jadwals->whereHasInstansiOf($request->instansi);
}
}
return DataTables::of($jadwals)
->addIndexColumn()
->make(true);
}
This should get a total of 1134 records and used to be working just fine. Now, when the error occurs, I get less than 100 records, and the last returned record is incomplete.
These different return syntaxes still giving me incomplete result.
return response()->json(
DataTables::of($jadwals)
->addIndexColumn()
->make(true)
);
return DataTables::of($jadwals)
->addIndexColumn()
->toJson();
return $jadwals->get();
return response()->json($jadwals->get());
However, these sintaxes is returning the complete 1134 records. But I can't use it as it's not using datatable's response format.
return dd($jadwals->get());
return $jadwals->get()->toJson();
And this is a data example of how an item/record should look like when returned completely, with 120 lines in total:
{
"id": 9999,
"kelas_periode_tahapan_id": 999,
"instruktur_id": 999,
"jumlah_pamong_yg_mengajar": 9,
"instruktur": {
"id": 9999,
"id_ref": 9999,
"nama": "Dr. Xxxxx",
"email": "xxxxxxxx#gmail.com",
"tgl_lahir": "95-09-9977",
"nip": "999999999999999999",
"nik": "99999999999999999",
"npwp": "99999999999999999",
"golongan_id": 9,
"jab_fungsional_id": 9,
"instansi_id": 9,
"no_rek": "99999999999",
"nama_bank": "BANK XXXXXXXX",
"bank_cabang": "XXX",
"nama_rek": "Xxxxxxxx Xxxxx Xxxxxxxxx",
"is_active": 9,
"golongan": {
"id": 9,
"description": "XXXXX",
"periodes": [
{
"id": 9,
"tahun_id": 9,
"periode": 9,
"pivot": {
"golongan_id": 9,
"periode_id": 9,
"pph_npwp": 9,
"pph_non_npwp": 9
}
}
]
},
"jab_fungsional": {
"id": 9,
"description": "Xxxxxxxx",
"periodes": [
{
"id": 9,
"tahun_id": 9,
"periode": 9,
"pivot": {
"jab_fungsional_id": 9,
"periode_id": 9,
"tarif": 99999999
}
}
]
},
"instansi": {
"id": 9,
"description": "Xxxxxxxxxxx Xxxxxxxxxxxxx Xxxxxxxxxxxx"
}
},
"kelas_periode_tahapan": {
"id": 999,
"kelas_id": 99,
"periode_tahapan_id": 99,
"is_verified": 9,
"is_locked": 9,
"kelas": {
"id": 99,
"periode_prodi_id": 9,
"description": "Xxxxxxxxxxx Xxxxxxxxxxxxx Xxxxxxxxxxxx",
"nama_grup_wa": "Xxxxxxxx Xxxxxxxxxxx",
"link_grup_wa": "https://xxxxxxxxxxxxxxxxxxxxxxxxx",
"periode_prodi": {
"id": 9,
"prodi_id": 9,
"periode_id": 9,
"prodi": {
"id": 9,
"nama": "Xxxxxxxxxxxxx Xxxxxxxxxxxxx",
"kode": "999",
"is_active": 9
}
}
},
"periode_tahapan": {
"id": 99,
"periode_id": 9,
"tahapan_id": 9,
"ket_hari_ke": 99,
"jadwal": "09-08-9099",
"materi": "Xxxxxxxxxxx Xxxxxxxx Xxxxxxxxxxxxxxxxxxxxx",
"jp_full": 9,
"jp_pamong": 9,
"tahapan": {
"id": 9,
"description": "Xxxxxxxxxxx Xxxxxxxxxxxxx Xxxxxxxxxxxx",
"akronim": "XXX",
"satuan": "XXX"
},
"periode": {
"id": 9,
"tahun_id": 9,
"periode": 9,
"tahun": {
"id": 9,
"tahun": 9099
},
"persentase_honor": {
"id": 9,
"periode_id": 9,
"full_dosen": 900,
"full_gpamong": 900,
"persentase_dosen": 99,
"persentase_gpamong": 99
}
}
}
},
"DT_RowIndex": 1
}
I am working on Magento2 [v2.4] Product integration use case.
I am creating a Product using REST API [postman] and observed that product price, color attributes are present in Request JSON but those are missing in Response received from Magento.
POST http://localhost/magento2/rest/V1/products
Request:
{
"product": {
"id": "2007",
"sku": "20210004",
"name": "Iphone 4",
"price": "400",
"status": 1,
"extension_attributes": {
"stock_item": {
"qty": 4,
"is_in_stock": "true"
}
},
"custom_attributes": [
{
"attribute_code": "color",
"value": 4
}
]
}
}
Response:
{
"id": 2007,
"sku": "20210004",
"name": "Iphone 4",
"attribute_set_id": 4,
"status": 1,
"visibility": 4,
"extension_attributes": {
"stock_item": {
"item_id": 18,
"product_id": 2007,
"stock_id": 1,
"qty": 4,
"is_in_stock": true,
"is_qty_decimal": false
}
},
"custom_attributes": [
{
"attribute_code": "options_container",
"value": "container2"
},
{
"attribute_code": "url_key",
"value": "iphone-4"
}
]
}
If you look at the request and response payload, you will see that Price and Color are there in request but somehow Magento did not honor those and got missed in response.
If I want to make this work, I had to re-send same payload again. Then I could see Price and Color in response.
Could you please suggest what is the issue here?
This is down to a bug in Magento (https://github.com/magento/magento2/issues/13639).
At the time of writing this should be fixed in 2.4.3. For versions 2.4.2 and lower you can add the following to your payload:
"type_id": "simple"
I have two tables a payments table and a tenants table. Each payments table can have many payments for a single tenant (one to many relationship)
Payments
id tenant_id amount
1 1 5000
2 1 6000
3 2 7000
4 2 8000
tenants
id name email
1 peter peter#info.com
2 grace grace#info.com
When i run the following in my controller
public function getPaymentsList(Request $request)
{
$payments = DB::table("payments")
->join('tenants','tenants.id','=','tenant_id')
->select('payments.id','payments.tenant_id','tenants.name','payments.rent_to')
->groupBy('tenant_id')->get()
;
return response()->json($payments);
}
}
I get json content of the oldest record in the payments table not the latest record.
[
{
"id": 1,
"tenant_id": 1,
"name": "peter",
"amount": "5000"
},
{
"id": 3,
"tenant_id": 2,
"name": "grace",
"amount": "7000"
},
]
The output i want is
[
{
"id": 2,
"tenant_id": 1,
"name": "peter",
"amount": "6000"
},
{
"id": 4,
"tenant_id": 2,
"name": "grace",
"amount": "8000"
},
]
How to improve the above query so that it can display the desired output?
you can use something like:
public function getPaymentsList(Request $request)
{
$payments = DB::table("payments")
->join('tenants','tenants.id','=','tenant_id')
->select('payments.id','payments.tenant_id','tenants.name','payments.rent_to')
->groupBy('tenant_id')->latest()->first()
;
return response()->json($payments);
}
}
check the larvel documents for useing latest()->first()
I just started exploring the elastic search and I stuck with a requirement in my project. I tried multiple thing but nothing worked for me. I have saved a sample document in elastic search index
"orderData": {
"lines": [
{
"lineNbr": 1,
"quantity": {
"amount": 1,
"uom": "EACH"
},
"weight": null,
"Qty": null
},
{
"lineNbr": 2,
"quantity": {
"amount": 1,
"uom": "EACH"
},
"weight": null,
"Qty": null
}
]
}
Next time I want to update only some of the data in line nbr one but here the problem is I dont want to do fields wise update. I get full Line Nbr 1 json again something like
{
"lineNbr": 1,
"quantity": {
"amount": 10,
"uom": "EACH"
},
"weight": 5,
"Qty": 5
}
But if I am performing update line nbr 2 tag is removed and only line nbr 1 tag is left with the updated data but I never wanted to touch line nbr 2
How can I achieve this? Any help will be appreciated. Thanks In Advance.
I want to design a checkbox tree structure using following data coming from Web API using Angular 6. How can I achieve it please help.
[
{
"id": 1,
"parent_id": 0,
"Fund_type":"A&P"
},
{
"id": 2,
"parent_id": 1,
"Fund_type": "On Invoice"
},
{
"id": 3,
"parent_id": 2,
"Fund_type": "Banded packs-Consumer"
},
{
"id": 4,
"parent_id": 2,
"Fund_type": "Banded packs-Shopper"
},....]
Where id=1 is the root node and id=2 is the direct child of it and id=3 &4 are direct children of id=2(You can understand the structure from parent_id )
Thanks.
You need to change your data as per the example given below and use this component:
https://www.npmjs.com/package/ngx-treeview
You can simply use angular tree view in
https://www.syncfusion.com/angular-ui-components/angular-treeview