php - Force using orderByWithPrefix() in a query list with JOIN
Get the solution ↓↓↓I'm using succesfully Backpack v.4.1 in a Laravel 8 project. Unfortunally, our client provides us an external Oracle db, not originally supported by Backpack. Thanks to yajra/laravel-oci8 package everythings works fine.
The only thing I need is to force to useorderByWithPrefix()
function for theListOperation
trait when a join is necessary.
It can be used only if the database driver belongs to the arraygetSqlDriverList()
(in filevendor/backpack/crud/src/app/Library/CrudPanel/CrudPanel.php
:162):
/**
* Get SQL driver list.
*
* @return array
*/
public function getSqlDriverList()
{
return ['mysql', 'sqlsrv', 'sqlite', 'pgsql'];
}
For my project, in order to work, I've changed the Query trait in this way (removing also the uselessgetSqlDriverList()
function):
diff --git a/src/app/Library/CrudPanel/Traits/Query.php b/src/app/Library/CrudPanel/Traits/Query.php
index 8a7453a1..ad802b97 100644
--- a/src/app/Library/CrudPanel/Traits/Query.php
+++ b/src/app/Library/CrudPanel/Traits/Query.php
@@ -145,7 +145,7 @@ trait Query
public function orderByWithPrefix($column_name, $column_direction = 'ASC')
{
- if ($this->driverIsSql()) {
+ if (null !== $this->query->getQuery()->joins) {
return $this->query->orderByRaw($this->model->getTableWithPrefix().'.'.$column_name.' '.$column_direction);
}
There is a better solution?
Thank you.
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: foreach() argument must be of type array|object, null given
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.