Skip to content

A free open source IT asset/license management system

Fix #6910: Add logic to manipulate the eloquent query. (#7006)

Ivan Nietod409be6d4357
diff --git a/app/Http/Controllers/Api/ConsumablesController.php b/app/Http/Controllers/Api/ConsumablesController.php
index 8a258dbea1..661eab4c5d 100644
--- a/app/Http/Controllers/Api/ConsumablesController.php
+++ b/app/Http/Controllers/Api/ConsumablesController.php
@@ -165,7 +165,7 @@ class ConsumablesController extends Controller
{
$consumable = Consumable::with(array('consumableAssignments'=>
function ($query) {
- $query->orderBy('created_at', 'DESC');
+ $query->orderBy($query->getModel()->getTable().'.created_at', 'DESC');
},
'consumableAssignments.admin'=> function ($query) {
},
diff --git a/app/Models/Company.php b/app/Models/Company.php
index 391a79d6b2..bb3467c38c 100644
--- a/app/Models/Company.php
+++ b/app/Models/Company.php
@@ -80,7 +80,13 @@ final class Company extends SnipeModel
}
$table = ($table_name) ? DB::getTablePrefix().$table_name."." : '';
- return $query->where($table.$column, '=', $company_id);
+
+ if(\Schema::hasColumn($query->getModel()->getTable(), $column)){
+ return $query->where($table.$column, '=', $company_id);
+ } else {
+ return $query->join('users as users_comp', 'users_comp.id', 'user_id')->where('users_comp.company_id', '=', $company_id);
+ }
+
}
public static function getIdFromInput($unescaped_input)