bosnadev / repository

Laravel Repositories is a package for Laravel 5 which is used to abstract the database layer. This makes applications much easier to maintain.
https://bosnadev.com
823 stars 233 forks source link

Call to undefined method findWhere #31

Open maxi032 opened 9 years ago

maxi032 commented 9 years ago

I am getting the above message and I don't know what I am doing wrong. I am calling the findWhere method from a view composer. Here is my code

<?php namespace App\Composers;

use Eventsapp\Repositories\SectionRepository; use Eventsapp\Repositories\PageRepository; use Eventsapp\Repositories\PostRepository;

class OnePageComposer{

protected $postsRepo, $pagesRepo, $sectionsRepo;

public function __construct(
    PageRepository $pagesRepo,
    SectionRepository $sectionsRepo,
    PostRepository $postsRepo,
    )
{
    $this->sectionsRepo = $sectionsRepo;
    $this->pagesRepo    = $pagesRepo;
    $this->postsRepo    = $postsRepo;
}

public function compose($view){
    $view->with([
        'sections' => $this->sectionsRepo->findWhere(['status'=>1]),
        'homepage' => $this->pagesRepo->getHomepage()
    ]);
}

} My SectionRepository looks like this:

<?php namespace App\Repositories;

use Bosnadev\Repositories\Contracts\RepositoryInterface; use Bosnadev\Repositories\Eloquent\Repository;

class SectionRepository extends Repository{

public function model() {
    return 'App\Models\Section';
}

}

appkr commented 9 years ago

Correct me if I'm wrong!

@maxi032 Hey! Now I'm studying this package. I have the same problem, so I looked into the code. Somehow findWhere method is no more available. Seems that you can achieve this by doing like this:

// If you only have a single query condition
$sections = $this->sectionRepo->findBy('status', '1');

// If you have more than two conditions
$this->sectionRepo->pushCriteria(new YourCriteria1);
$this->sectionRepo->pushCriteria(new YourCriteria2);
$sections = $this->sectionRepo->all();

UPDATE. Oh! I found findWhere() method at Eloquent/Repository.php.

jdsingh commented 9 years ago

You need to install master branch in your project in order to access findWhere method.

mirzap commented 9 years ago

I'll tag latest version today ;)

OxMarco commented 9 years ago

Same here, just cannot find any reference to "findWhere" in the code

carlituxman commented 9 years ago

in the vendor version obtain by composer not find findWhere and others like findAllBy ...

is not tagged the last version

mirzap commented 9 years ago

Tagged, sorry took me too long :)