The bizarre problem of laravel orm where condition failure.

abstract class BaseRepositoryApi extends \Prettus\Repository\Eloquent\BaseRepository
{
    public function paginate($perPage = null, $page = null, $columns = ["*"])
    {
        $userModel = new User();
        $userModel->where("user_type","seller");
        $result = $userModel->paginate($perPage,$columns,null,$perPage);
        return $result;
    }
}

write that when this method is called, the where condition will not take effect.

however, if you write the code in the paginate method directly into controller, the where condition will apply correctly.

what the hell is this for?

my code is not written in controller

Mar.30,2021

try this

        $userModel = new User();
        $query = $userModel->where('user_type','seller');
        $result = $query->paginate($perPage,$columns,null,$perPage);

in addition, I don't understand why I wrote it this way. Since I used PrettusRepository, I should follow the way this package is written.

this is why the paginate method of the base class BaseRepositoryApi directly fetches the data of User.

query builder in

Orm seems to be a single case

.
Menu