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.
|
2023-04-26 15:17:49 +02:00
|
|
|
* @param Builder $query
|
|
|
|
* @param array $columns
|
2023-02-16 02:36:09 +01:00
|
|
|
*
|
2023-04-26 16:16:07 +02:00
|
|
|
* @return Builder
|
2023-01-21 06:52:24 +01:00
|
|
|
*/
|
2023-04-26 15:17:49 +02:00
|
|
|
public function scopeExclude($query, $columns): \Illuminate\Database\Eloquent\Builder
|
2023-01-21 06:52:24 +01:00
|
|
|
{
|
2023-04-26 16:16:07 +02:00
|
|
|
/** @var Builder $query */
|
2023-01-21 06:52:24 +01:00
|
|
|
return $query->select(array_diff($this->getTableColumns(), (array) $columns));
|
|
|
|
}
|
|
|
|
}
|