I'm new to Laravel. I'm creating a json structure using a function. This is my current output:
{
"success": "1",
"data": [
{
"category_type_id": 1,
"category_type": "Study",
"category_icon": "http://192.168.1.132:8000/images/category/study.svg"
},
{
"category_type_id": 2,
"category_type": "Sports",
"category_icon": "http://192.168.1.132:8000/images/category/game.svg"
},
{
"category_type_id": 3,
"category_type": "Other",
"category_icon": "http://192.168.1.132:8000/images/category/other.svg"
}
]
}
This is my controller code:
$get_all_category = CategoryType::all();
return response()->json(['success' => '1', 'data' => $get_all_category]);
I want result without array that is started from data plz need solution
Just remove the other attributes from your from your json response:
$get_all_category = CategoryType::all();
return response()->json($get_all_category);
That will return your json like this:
[
{
"category_type_id": 1,
"category_type": "Study",
"category_icon": "http://192.168.1.132:8000/images/category/study.svg"
},
{
"category_type_id": 2,
"category_type": "Sports",
"category_icon": "http://192.168.1.132:8000/images/category/game.svg" },
{
"category_type_id": 3
"category_type": "Other",
"category_icon": "http://192.168.1.132:8000/images/category/other.svg"
}
]
If you want to keep the success atribute you can do something like this, but it would just change the old data attribute you want to get rid of to '0':
$get_all_category = CategoryType::all();
return response()->json(['success' =>'1', $get_all_category]);