1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-14 15:13:29 +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
*
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-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-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-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));
}
}