I am trying to filter the data from my custom table, But it is throwing Error.
Fatal error: Cannot redeclare class Test\Learning\ResourceModel\Learning\Collection in C:\xampp\htdocs\demo\app\code\Test\Learning\Model\ResourceModel\Learning\Collection.php on line 24
Block/Learning.php
<?php
namespace Test\Learning\Block;
class Learning extends \Magento\Framework\View\Element\Template
{
/**
* @var \Test\Learning\Model\LearningFactory
*/
protected $_learningFactory;
public function __construct
(
\Magento\Framework\View\Element\Template\Context $context,
\Test\Learning\Model\LearningFactory $learningFactory,
array $data = []
)
{
parent::__construct($context, $data);
$this->_learningFactory = $learningFactory;
}
public function getFilterData(){
$customerId = "1";
$data = $this->_learningFactory->create()->getCollection()->addFieldToFilter(array('customer_id',$customerId));
foreach ($data as $k => $v) {
}
return $data;
}
}
Model/Learning/ResourceModel/Learning/Collection.php
<?php
namespace Test\Learning\ResourceModel\Learning;
class Collection extends \Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection
{
/**
* @var string
*/
protected $_idFieldName = 'clul_id';
/**
* Define resource model
*
* @return void
*/
protected function _construct()
{
$this->_init('Test\Learning\Model\Learning', 'Test\Learning\Model\ResourceModel\Learning');
$this->_map['fields']['clul_id'] = 'main_table.clul_id';
}
}
/view/frontend/templates/learning.phtml
<?php echo $block->getFilterData(); ?>
Any help On this?
Test\Learning\Model\ResourceModel\Learning
insteadTest\Learning\ResourceModel\Learning
in Collection..