Hi Abdelrahman Omran. Yesterday didn't had enough time to test your package and posted an issue based on code read only. Didn't mean to be rude and I'm sorry if the post sounds like it. I really appreciate your work.
Today got some time and started with a fresh laravel install and a simple database I use for development: Posts, Comments and Authors. Really simple structure with dummy data.
This is what I have and the errors that I found. Perhaps I am making some mistakes here but just followed your docs.
PostRepository
<?php
namespace App\Repositories;
use App\Models\Post;
use Illuminate\Container\Container as Application;
use Rinvex\Repository\Repositories\EloquentRepository;
class PostRepository extends EloquentRepository
{
// Instantiate repository object with required data
public function __construct(Application $app)
{
$this->setContainer($app)
->retrieveModel(Post::class)
->setRepositoryId('rinvex.repository');
}
public function getPost10()
{
return $this->findWhere(['post_id', '<=', 10]);
}
}
IndexController
<?php
namespace App\Http\Controllers;
use App\Http\Requests;
use App\Repositories\PostRepository;
class IndexController extends Controller
{
private $repository;
public function __construct(PostRepository $repository)
{
$this->repository = $repository;
}
public function index()
{
$post20 = $this->repository->getPost10();
return $post20;
}
}
The application throws an error:
BadMethodCallException in Builder.php line 2345:
Call to undefined method Illuminate\Database\Query\Builder::setRepositoryId()
in Builder.php line 2345
at Builder->__call('setRepositoryId', array('rinvex.repository'))
at call_user_func_array(array(object(Builder), 'setRepositoryId'), array('rinvex.repository')) in Builder.php line 1402
at Builder->__call('setRepositoryId', array('rinvex.repository'))
at call_user_func_array(array(object(Builder), 'setRepositoryId'), array('rinvex.repository')) in Model.php line 3505
at Model->__call('setRepositoryId', array('rinvex.repository')) in PostRepository.php line 16
at PostRepository->__construct(object(Application))
at ReflectionClass->newInstanceArgs(array(object(Application))) in Container.php line 779
at Container->build('App\Repositories\PostRepository', array()) in Container.php line 629
at Container->make('App\Repositories\PostRepository', array()) in Application.php line 697
at Application->make('App\Repositories\PostRepository') in Container.php line 849
at Container->resolveClass(object(ReflectionParameter)) in Container.php line 804
at Container->getDependencies(array(object(ReflectionParameter)), array()) in Container.php line 773
...
Then read about Automatic Guessing in the docs and commented the __construct() method in PostRepository.php
Another error
FatalThrowableError in EloquentRepository.php line 150:
Call to a member function toSql() on null
in EloquentRepository.php line 150
at EloquentRepository->findWhere(array('post_id', '<=', '10')) in PostRepository.php line 21
at PostRepository->getPost10() in IndexController.php line 19
at IndexController->index()
Line 150: $cacheKey = md5(json_encode([$where, $columns, $with, $lifetime, $driver, $this->model->toSql()]));
$this->model is null
Can you give me some feedback? I would like to test the improvements on the caching system.
Thanks in advance.
Cheers