1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-09-21 17:01:33 +02:00
invoiceninja/app/Models/Traits/Excludable.php

38 lines
847 B
PHP
Raw Normal View History

2023-01-21 06:52:24 +01:00
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
2023-01-28 23:21:40 +01:00
* @copyright Copyright (c) 2023. Invoice Ninja LLC (https://invoiceninja.com)
2023-01-21 06:52:24 +01:00
*
* @license https://www.elastic.co/licensing/elastic-license
*/
namespace App\Models\Traits;
2023-02-16 02:36:09 +01:00
trait Excludable
{
2023-01-21 06:52:24 +01:00
/**
* Get the array of columns
2023-02-16 02:36:09 +01:00
*
2023-01-21 06:52:24 +01:00
* @return mixed
*/
2023-02-16 02:36:09 +01:00
private function getTableColumns()
{
2023-01-21 06:52:24 +01:00
return $this->getConnection()->getSchemaBuilder()->getColumnListing($this->getTable());
}
/**
* Exclude an array of elements from the result.
* @param $query
* @param $columns
2023-02-16 02:36:09 +01:00
*
2023-01-21 06:52:24 +01:00
* @return mixed
*/
public function scopeExclude($query, $columns)
{
return $query->select(array_diff($this->getTableColumns(), (array) $columns));
}
}