It is my code in which I get the subcategories' names. But the problem is it shows data in an array form.
$couponCategory = Coupon::select('categories')->where('expiry_date', '>', $dt)->where('status', 1)->first();
$couponsCat = explode(',', $couponCategory);
$categoriesDetails = Category::select('category_name')->whereIn('id', $couponsCat)->whereNotIn('parent_id', [0, 0])->get()->toArray();
str_replace("'", "\'", json_encode($categoriesDetails));
echo "<pre>";
print_r($categoriesDetails);
die;
Result
Array
(
[0] => Array
(
[category_name] => Casual T-Shirts
)
[1] => Array
(
[category_name] => Formal T-Shirt
)
)
I also try to convert it into a string but the output is like
[{"category_name":"Casual T-Shirts"},{"category_name":"Formal T-Shirt"}]
I want the result just display the name Casual T-Shirts and Formal T-Shirt no brackets or anything in string formate