Laravel-Backpack / CRUD

Build custom admin panels. Fast!
https://backpackforlaravel.com
MIT License
3.08k stars 885 forks source link

[Bug] #3465

Closed zenia9012 closed 3 years ago

zenia9012 commented 3 years ago

Bug report

What I did

I have 2 databases in the project, and I provide connection in the model:

protected $connection = 'database1'; protected $connection = 'database2';

two models are connected with an eloquent relationship (tables in different databases)

I use "select" column type, and I need to add search logic in a connected column.

What I expected to happen

Need to add search to the connected column from another database.

What happened

https://backpackforlaravel.com/docs/4.1/crud-columns#custom-search-logic-for-columns

I use this "searchLogic", but I got the error:

General error: 1 no such table: table2

What I've already tried to fix it

I think it happened because in "$this->crud->query" looking for this table in first database.

Backpack, Laravel, PHP, DB version

Laravel 8.6.0 PHP 7.3.25 MySQL 5.7 Backpack 4.1.25

When I run php artisan backpack:version the output is:

LARAVEL VERSION:

v8.6.0@a71952a6dba55de0bb11b5fbbd84874eda2a755c

BACKPACK VERSION:

4.1.25@23fb1ed5153d5465d49d2fe1ca265a5985c78877

welcome[bot] commented 3 years ago

Hello there! Thanks for opening your first issue on this repo!

Just a heads-up: Here at Backpack we use Github Issues only for tracking bugs. Talk about new features is also acceptable. This helps a lot in keeping our focus on improving Backpack. If you issue is not a bug/feature, please help us out by closing the issue yourself and posting in the appropriate medium (see below). If you're not sure where it fits, it's ok, a community member will probably reply to help you with that.

Backpack communication channels:

Please keep in mind Backpack offers no official / paid support. Whatever help you receive here, on Gitter, Slack or Stackoverflow is thanks to our awesome awesome community members, who give up some of their time to help their peers. If you want to join our community, just start pitching in. We take pride in being a welcoming bunch.

Thank you!

-- Justin Case The Backpack Robot

pxpm commented 3 years ago

Hello @zenia9012

I am sorry but I could not fully understand your question, nor I think it's clear what you want to achieve.

As far as I know, each model can only have one $connection defined, usually what packages like multi-tenancy does is switching the connection on middleware, before it reaches the controller/model.

I would advise you to post this question to stackoverflow with FULL code example (model/seachLogic code etc etc), maybe try using raw queries, or ignore the previous crud query and start a new Builder instance yourself, I mean, don't start from $this->crud->query and set it to whatever you want $this->crud->query = .....

I don't think this is a bug in backpack, it's how things works and is expected to work.

I am going to close this issue, if you think I am wrong, and I am a lot of times, please re-open.

Best, Pedro