I am trying to return the collection factory from database , it is giving an array now i convert it to json using JSON Encode function but it is returnig a string with backslashes !!
Code for Api Interface
<?php
namespace FME\MobileApp\Api;
interface SliderInterface
{
/**
* @return Object
*/
public function getImages();
}
Code for API
<?php
namespace FME\MobileApp\Model\Api;
use \FME\MobileApp\Model\ImgFactory;
class SliderImages {
protected $modelFactory;
public $_storeManager;
public function __construct(
ImgFactory $modelFactory ,
\Magento\Store\Model\StoreManagerInterface $storeManager
)
{
$this->modelFactory = $modelFactory;
$this->_storeManager=$storeManager;
}
/**
* @inheritdoc
*/
public function getImages()
{
$baseurl = $this->_storeManager->getStore()->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_MEDIA);
$photogallery_id = 1;
$model = $this->modelFactory->create()->getCollection()
->addFieldToFilter('photogallery_id',$photogallery_id);
$results = $model->getData();
return json_encode($results);
}
}
Output
"[{"img_id":"1","img_name":"\/6\/1\/619c5e9c0fe4d_6.jpg","img_label":"","img_url":"http:\/\/localhost\/m2422\/pub\/media\/mobapp\/images\/6\/1\/619c5e9c0fe4d_6.jpg","photogallery_id":"1","img_order":"1","disabled":"0","img_description":"","tags":""}]"