It is recommended that you extend and make custom functions within Repositories. To do this, we simple extend our AbstractRepository class.
AbstractRepository gives you few methods:
PHP:
namespace MyAddonId\Repository;
use \MyDownloads\Repository\AbstractRepository;
class MyCustomRepository extends AbstractRepository
{
/*
We must implement abstracted public method getContentType()
to be able to access to getModel() eloquent model
*/
public function getContentType()
{
return 'Groups'; // We will make instanceof model Groups, so later when we will do $this->getModel() will return model.
}
public function myCustomMethod()
{
// To access Model instance we simple run:
$this->getModel(); // Will return eloquent model instance
}
}
AbstractRepository gives you few methods:
- getModel() // will return instance of the eloquent model.
- finder ( Currently in development )
- insertRecord(array $data) // accept array data and insert it to the model. This does not validate for multiple data