Dostlar merhaba böyle bir kodum var json da verilerim var şu şekilde
{
"en": "Classic Wash Months",
"tr": "Classic Wash Aylık"
}
title başlığı altında yer alıyorlar bu şekilde ben istiyorum ki Accept-Language'den en gelirse en başlığını göndereyim tr gelirse tr'yi göndereyim bu package_properties için de geçerli orda da value'ya bunu uygulamam gerekiyor
İlişkisi bu şekilde. Bir türlü başaramadım Dil yapısına göre bu json veriyi filtreleyip sadece o başlığı göndermeyi
public function packageProperty(){
return $this->hasMany(PackageProperty::class, 'package_id','id');
}
public function all(Request $request)
{
$type = $request->input('type');
$currency = $request->input('currency') ? strtoupper($request->input('currency')) : 'TRY';
$carType = $request->input('car_type');
$query = Package::with('packageProperty')->where('package_type', 'subscription');
if ($type && in_array($type, ['week', 'monthly', '3monthly', '6monthly', 'yearly'])) {
$query->where('subscription_type', $type);
}
if ($carType) {
if (in_array(strtolower($carType), ['otomobil', 'pickup', 'suv', 'ambulance', 'bus', 'truck', 'minibus', 'van', 'default'])) {
$query->whereRaw('LOWER(car_type) = ?', [strtolower($carType)]);
}
}
$data = $query->get();
$orderedData = $data->sortBy(function($package) {
switch ($package->name) {
case 'EKO':
return 1;
case 'STANDART':
return 2;
case 'lux':
return 3;
case 'ULTRA LUX':
return 4;
default:
return 5;
}
})->values();
if ($currency != "TRY") {
$convertedPrices = $this->convertPrices($orderedData, $currency);
$orderedData = $convertedPrices;
}
return new SuccessJsonResource($orderedData);
}
Postman çıktısı da ekleyeyimm
{
"status": 200,
"message": "Success",
"data": [
{
"id": 1,
"title": {
"en": "Classic Wash Months",
"tr": "Classic Wash Aylık"
},
"package_type": "subscription",
"wash_quantity": 10,
"price": "100.00",
"created_at": "2024-06-07T18:16:02.000000Z",
"updated_at": "2024-07-04T18:32:01.000000Z",
"product_id": 1,
"reference_code": "7a9942ac-8855-4bd3-9127-ec22aaa9275e",
"images": null,
"icons": null,
"discount": null,
"hatchback_price": null,
"sedan_price": null,
"SUV_price": null,
"bus_price": null,
"truck_price": null,
"currency": "TRY",
"car_type": "SUV",
"subscription_type": "weeks",
"package_property": [
{
"id": 4,
"package_id": 1,
"value": {
"en": "test",
"tr": "english test"
},
"created_at": "2024-07-04T19:13:20.000000Z",
"updated_at": "2024-07-04T19:13:29.000000Z",
"icons": null
}
]
},
{
"id": 2,
"title": {
"en": "English Aciklama",
"tr": "Classic Wash Yıllık"
},
"package_type": "subscription",
"wash_quantity": 150,
"price": "1000.00",
"created_at": "2024-06-07T18:16:02.000000Z",
"updated_at": "2024-07-04T13:31:09.000000Z",
"product_id": 1,
"reference_code": "da3ce4e1-efb8-4a8a-abe2-0a854ecdb74e",
"images": null,
"icons": null,
"discount": null,
"hatchback_price": null,
"sedan_price": null,
"SUV_price": null,
"bus_price": null,
"truck_price": null,
"currency": "TRY",
"car_type": "truck",
"subscription_type": "weeks",
"package_property": [
{
"id": 3,
"package_id": 2,
"value": {
"tr": "test",
"en": ""
},
"created_at": "2024-07-04T13:27:55.000000Z",
"updated_at": "2024-07-04T13:27:55.000000Z",
"icons": "test"
}
]
},
{
"id": 3,
"title": {
"en": "English Aciklama",
"tr": "Classic Wash Yıllık"
},
"package_type": "subscription",
"wash_quantity": 30,
"price": "300.00",
"created_at": "2024-06-07T18:16:02.000000Z",
"updated_at": "2024-06-28T19:18:05.000000Z",
"product_id": 1,
"reference_code": "b3f20015-a8c4-4ad8-a81d-18ebe6e17812",
"images": null,
"icons": null,
"discount": null,
"hatchback_price": null,
"sedan_price": null,
"SUV_price": null,
"bus_price": null,
"truck_price": null,
"currency": "TRY",
"car_type": "bus",
"subscription_type": "weeks",
"package_property": []
},
{
"id": 4,
"title": {
"en": "English Aciklama",
"tr": "Classic Wash Yıllık"
},
"package_type": "subscription",
"wash_quantity": 300,
"price": "3000.00",
"created_at": "2024-06-07T18:16:02.000000Z",
"updated_at": "2024-06-07T18:16:02.000000Z",
"product_id": 1,
"reference_code": "caa72f8b-80d9-4c6a-b75c-763e73244d57",
"images": null,
"icons": null,
"discount": null,
"hatchback_price": null,
"sedan_price": null,
"SUV_price": null,
"bus_price": null,
"truck_price": null,
"currency": "TRY",
"car_type": "pickup",
"subscription_type": "weeks",
"package_property": []
},
{
"id": 5,
"title": {
"en": "English Aciklama",
"tr": "Classic Wash Yıllık"
},
"package_type": "subscription",
"wash_quantity": 30,
"price": "300.00",
"created_at": "2024-06-07T18:16:02.000000Z",
"updated_at": "2024-06-07T18:16:02.000000Z",
"product_id": 1,
"reference_code": "910469fd-0fd1-4e56-93c4-41d792b33103",
"images": null,
"icons": null,
"discount": null,
"hatchback_price": null,
"sedan_price": null,
"SUV_price": null,
"bus_price": null,
"truck_price": null,
"currency": "TRY",
"car_type": "van",
"subscription_type": "weeks",
"package_property": []
},
{
"id": 6,
"title": {
"en": "English Aciklama",
"tr": "Classic Wash Yıllık"
},
"package_type": "subscription",
"wash_quantity": 300,
"price": "3000.00",
"created_at": "2024-06-07T18:16:02.000000Z",
"updated_at": "2024-06-07T18:16:02.000000Z",
"product_id": 1,
"reference_code": "cb7c866a-0e86-4950-8e3d-3dd328afbf0c",
"images": null,
"icons": null,
"discount": null,
"hatchback_price": null,
"sedan_price": null,
"SUV_price": null,
"bus_price": null,
"truck_price": null,
"currency": "TRY",
"car_type": "ambulance",
"subscription_type": "weeks",
"package_property": []
},
{
"id": 7,
"title": {
"en": "English Aciklama",
"tr": "Classic Wash Yıllık"
},
"package_type": "subscription",
"wash_quantity": 50,
"price": "500.00",
"created_at": "2024-06-07T18:16:02.000000Z",
"updated_at": "2024-06-25T08:01:48.000000Z",
"product_id": 1,
"reference_code": "e454a22e-81af-4d18-9b9a-28dc6ebbcb57",
"images": "https://i.hizliresim.com/i98a6y2.png",
"icons": "https://i.hizliresim.com/i98a6y2.png",
"discount": null,
"hatchback_price": null,
"sedan_price": null,
"SUV_price": null,
"bus_price": null,
"truck_price": null,
"currency": "TRY",
"car_type": "default",
"subscription_type": "weeks",
"package_property": [
{
"id": 1,
"package_id": 7,
"value": {
"tr": "Test Özellik",
"en": ""
},
"created_at": "2024-06-25T08:07:05.000000Z",
"updated_at": "2024-06-25T08:07:05.000000Z",
"icons": "https://i.hizliresim.com/i98a6y2.png"
}
]
},
{
"id": 8,
"title": {
"en": "English Aciklama",
"tr": "Classic Wash Yıllık"
},
"package_type": "subscription",
"wash_quantity": 500,
"price": "5000.00",
"created_at": "2024-06-07T18:16:02.000000Z",
"updated_at": "2024-06-07T18:16:02.000000Z",
"product_id": 1,
"reference_code": "ba23beb1-bfbf-4c77-b7aa-4f89f2462454",
"images": null,
"icons": null,
"discount": null,
"hatchback_price": null,
"sedan_price": null,
"SUV_price": null,
"bus_price": null,
"truck_price": null,
"currency": "TRY",
"car_type": "default",
"subscription_type": "weeks",
"package_property": []
},
{
"id": 12,
"title": {
"en": "English Aciklama",
"tr": "Classic Wash Yıllık"
},
"package_type": "subscription",
"wash_quantity": 74,
"price": "450.66",
"created_at": "2024-06-28T18:24:31.000000Z",
"updated_at": "2024-06-28T18:24:31.000000Z",
"product_id": 1,
"reference_code": null,
"images": "Vel voluptatibus non",
"icons": null,
"discount": 13,
"hatchback_price": null,
"sedan_price": null,
"SUV_price": null,
"bus_price": null,
"truck_price": null,
"currency": "USD",
"car_type": "default",
"subscription_type": "weeks",
"package_property": [
{
"id": 2,
"package_id": 12,
"value": {
"tr": "Omnis molestias simi",
"en": ""
},
"created_at": "2024-06-28T18:24:31.000000Z",
"updated_at": "2024-06-28T18:24:31.000000Z",
"icons": "Voluptas rerum disti"
}
]
}
]
}