Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

create legacy laravel model builder methods? #154

Open
shopapps opened this issue Sep 1, 2022 · 0 comments
Open

create legacy laravel model builder methods? #154

shopapps opened this issue Sep 1, 2022 · 0 comments

Comments

@shopapps
Copy link

shopapps commented Sep 1, 2022

Hi,

Just discovered this project and am interested to see how it performs against laravel-mongodb

to do this we have lots of legacy laravel model builder methods that will need to have equivalents. I'm happy to write the overrides but need some pointers on getting started.

for example to use livewire-datatables a builder needs to be returned from an example query of:

public function query()
{
         return Order::query()
                    ->when($this->getFilter('search'), function($query, $term){
                        $query = $query->search((string)$term);
                        $query = $query->searchCustomer((string)$term);
                        $query = $query->searchExtras((string)$term);
                        return $query;
                    })
                    ->when($this->getFilter('status'), fn($query, $status) => $query->statusSearch((int)$status))
                    ->whereNull(Order::CANCELLED_AT)
                    ->orderBy(Order::CREATED_AT, 'desc');
}

then later in code, it calls

$query->paginate();

to return a LAP object.

So in this instance I need to create new methods for query(), when() , whereNull() , OrderBy() and paginate() which (I assume) will be via an extended Query/Builder.php (??) class

is this viable? is there a better way of handling this?

my start point was to override the MongolidModel with something like:

namespace App\Models\Overrides\Mongolid;

use MongolidLaravel\MongolidModel as BaseMongolidModel;

class MongolidModel extends BaseMongolidModel
{
    public static function query() {
//        return (new static())->getLocalMock();
          return Container::make(Builder::class);
    }
}

what would you suggest I return in the initial ->query() call? :-)

thanks in advance for any help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant