Using magento 2.2
, CRUD
, API
. I got an error while try to access method getCollection().
{ "messages": { "error": [ { "code": 500, "message": "Fatal Error: 'Cannot declare class Iota\EShopping\Model\ResourceMode\Social\Collection, because the name is already in use' in '/home/esh_www/app/code/Iota/EShopping/Model/ResourceModel/Social/Collection.php' on line 20", "trace": "Trace is not available." } ] } }
CALL
use Magento\Customer\Model\CustomerFactory;
use Iota\EShopping\Model\SocialFactory;
use Iota\EShopping\Setup\SchSocialLogin;
use Iota\EShopping\Api\Data\SocialLoginModel as Login;
/**
*
* @author channarith.bong
*
*/
class CustomerManagement implements \Iota\EShopping\Api\CustomerManagementInterface
{
/**
*
* @param SocialFactory $socialFactory
* @param CustomerFactory $customerFactory
*/
public function __construct(
SocialFactory $socialFactory,
CustomerFactory $customerFactory
){
$this->customerFactory = $customerFactory;
$this->socialFactory = $socialFactory;
}
/**
*
* @return string
*/
public function validateCustomerLogin()
{
$socialCollection = $this->socialFactory->create()->getCollection();
}
}
Model
<?php
namespace Iota\EShopping\Model;
use Magento\Framework\Data\Collection\AbstractDb;
use Magento\Framework\Model\AbstractModel;
use Magento\Framework\Model\Context;
use Magento\Framework\Model\ResourceModel\AbstractResource;
use Magento\Framework\Registry;
/**
*
* @author channarith.bong
*
*/
class Social extends AbstractModel
{
/**
*
* @param Context $context
* @param Registry $registry
* @param AbstractResource $resource
* @param AbstractDb $resourceCollection
* @param array $data
*/
public function __construct(
Context $context,
Registry $registry,
AbstractResource $resource = null,
AbstractDb $resourceCollection = null,
array $data = []
){
parent::__construct($context, $registry, $resource, $resourceCollection, $data);
}
/**
* Define resource model
*/
protected function _construct()
{
$this->_init('Iota\EShopping\Model\ResourceModel\Social');
}
}
Collection
<?php
namespace Iota\EShopping\Model\ResourceMode\Social;
use Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection;
/**
*
* @author channarith.bong
*
*/
class Collection extends AbstractCollection
{
/**
* Define model & resource model
*/
protected function _construct()
{
$this->_init('Iota\EShopping\Model\Social', 'Iota\EShopping\Model\ResourceModel\Social');
}
}
Resource
<?php
namespace Iota\EShopping\Model\ResourceModel;
use Magento\Framework\Model\ResourceModel\Db\AbstractDb;
/**
*
* @author channarith.bong
*
*/
class Social extends AbstractDb
{
/**
* Define main table
*/
protected function _construct()
{
$this->_init('iot_td_social_login', 'id');
}
}
php bin/magento cache:flush
andphp bin/magento setup:di:compile
Mode Developer
, I usedphp bin/magento cache:flush
andphp bin/magento setup:di:compile
namespace Iota\EShopping\Model\ResourceMode\Social;
Tonamespace Iota\EShopping\Model\ResourceModel\Social;
in yourCollection.php
and same for folder name FromResourceMode
ToResourceModel
?