1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-16 08:02:40 +01:00
invoiceninja/app/Models/Traits/Excludable.php

53 lines
1.6 KiB
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
*
2024-04-12 06:15:41 +02:00
* @copyright Copyright (c) 2024. 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-04-27 00:05:57 +02:00
use Illuminate\Support\Facades\Schema;
2023-04-26 23:46:59 +02:00
/**
* @method static Builder scopeExclude(array $columns)
* @method static Builder exclude(array $columns)
2023-04-26 23:46:59 +02:00
* @template TModelClass of \Illuminate\Database\Eloquent\Model
* @extends \Illuminate\Database\Eloquent\Builder<TModelClass>
* @mixin \Illuminate\Database\Eloquent\Builder
*/
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-04-27 00:05:57 +02:00
/** @var Schema|\App\Models\BaseModel $this */
2023-01-21 06:52:24 +01:00
return $this->getConnection()->getSchemaBuilder()->getColumnListing($this->getTable());
}
/**
* Exclude an array of elements from the result.
2023-10-26 04:57:44 +02:00
*
2023-08-06 09:03:12 +02:00
* @method static \Illuminate\Database\Eloquent\Builder<static> exclude($columns)
* @method static \Illuminate\Database\Eloquent\Builder<static> exclude($columns)
2023-10-26 04:57:44 +02:00
*
2023-07-26 04:59:36 +02:00
* @param \Illuminate\Database\Eloquent\Builder $query
2023-04-26 15:17:49 +02:00
* @param array $columns
2023-02-16 02:36:09 +01:00
*
2023-07-26 04:59:36 +02:00
* @return \Illuminate\Database\Eloquent\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-27 00:05:57 +02:00
/** @var \Illuminate\Database\Eloquent\Builder|static $query */
2023-01-21 06:52:24 +01:00
return $query->select(array_diff($this->getTableColumns(), (array) $columns));
}
}