2019-09-10 04:30:43 +02:00
|
|
|
<?php
|
|
|
|
/**
|
2020-09-06 11:38:10 +02:00
|
|
|
* Invoice Ninja (https://invoiceninja.com).
|
2019-09-10 04:30:43 +02:00
|
|
|
*
|
|
|
|
* @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)
|
2019-09-10 04:30:43 +02:00
|
|
|
*
|
2021-06-16 08:58:16 +02:00
|
|
|
* @license https://www.elastic.co/licensing/elastic-license
|
2019-09-10 04:30:43 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
|
|
|
use App\Utils\Traits\MakesHash;
|
2019-09-11 07:32:47 +02:00
|
|
|
use Illuminate\Database\Eloquent\Model;
|
2023-01-29 09:56:13 +01:00
|
|
|
use Illuminate\Database\Eloquent\ModelNotFoundException as ModelNotFoundException;
|
2023-02-16 02:36:09 +01:00
|
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
2019-09-10 04:30:43 +02:00
|
|
|
|
2023-03-08 08:33:42 +01:00
|
|
|
/**
|
|
|
|
* App\Models\GroupSetting
|
|
|
|
*
|
|
|
|
* @property int $id
|
|
|
|
* @property int $company_id
|
|
|
|
* @property int|null $user_id
|
|
|
|
* @property string|null $name
|
|
|
|
* @property object|null $settings
|
|
|
|
* @property int $is_default
|
|
|
|
* @property int|null $deleted_at
|
|
|
|
* @property int|null $created_at
|
|
|
|
* @property int|null $updated_at
|
|
|
|
* @property int $is_deleted
|
|
|
|
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Client> $clients
|
|
|
|
* @property-read int|null $clients_count
|
|
|
|
* @property-read \App\Models\Company $company
|
|
|
|
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Document> $documents
|
|
|
|
* @property-read int|null $documents_count
|
|
|
|
* @property-read mixed $hashed_id
|
|
|
|
* @property-read \App\Models\User|null $user
|
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|StaticModel company()
|
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|StaticModel exclude($columns)
|
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|GroupSetting newModelQuery()
|
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|GroupSetting newQuery()
|
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|GroupSetting onlyTrashed()
|
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|GroupSetting query()
|
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|GroupSetting whereCompanyId($value)
|
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|GroupSetting whereCreatedAt($value)
|
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|GroupSetting whereDeletedAt($value)
|
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|GroupSetting whereId($value)
|
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|GroupSetting whereIsDefault($value)
|
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|GroupSetting whereIsDeleted($value)
|
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|GroupSetting whereName($value)
|
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|GroupSetting whereSettings($value)
|
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|GroupSetting whereUpdatedAt($value)
|
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|GroupSetting whereUserId($value)
|
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|GroupSetting withTrashed()
|
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|GroupSetting withoutTrashed()
|
|
|
|
* @mixin \Eloquent
|
|
|
|
*/
|
2019-09-12 03:28:41 +02:00
|
|
|
class GroupSetting extends StaticModel
|
2019-09-10 04:30:43 +02:00
|
|
|
{
|
2019-12-30 22:59:12 +01:00
|
|
|
use MakesHash;
|
2020-02-27 00:32:44 +01:00
|
|
|
use SoftDeletes;
|
2020-09-06 11:38:10 +02:00
|
|
|
|
2019-09-10 04:30:43 +02:00
|
|
|
protected $casts = [
|
2019-09-26 00:27:26 +02:00
|
|
|
'settings' => 'object',
|
|
|
|
'updated_at' => 'timestamp',
|
|
|
|
'created_at' => 'timestamp',
|
|
|
|
'deleted_at' => 'timestamp',
|
2019-09-10 04:30:43 +02:00
|
|
|
];
|
|
|
|
|
2019-10-05 00:58:51 +02:00
|
|
|
protected $fillable = [
|
2019-12-30 22:59:12 +01:00
|
|
|
'name',
|
2020-09-06 11:38:10 +02:00
|
|
|
'settings',
|
2019-10-05 02:11:04 +02:00
|
|
|
];
|
2019-10-05 00:58:51 +02:00
|
|
|
|
2021-08-30 07:35:37 +02:00
|
|
|
protected $appends = [
|
|
|
|
'hashed_id',
|
|
|
|
];
|
|
|
|
|
|
|
|
public function getHashedIdAttribute()
|
|
|
|
{
|
|
|
|
return $this->encodePrimaryKey($this->id);
|
|
|
|
}
|
2022-06-21 11:57:17 +02:00
|
|
|
|
2020-07-23 05:55:11 +02:00
|
|
|
protected $touches = [];
|
2020-07-16 13:01:39 +02:00
|
|
|
|
2019-12-30 22:59:12 +01:00
|
|
|
public function company()
|
|
|
|
{
|
|
|
|
return $this->belongsTo(Company::class);
|
|
|
|
}
|
2019-09-10 04:30:43 +02:00
|
|
|
|
2019-12-30 22:59:12 +01:00
|
|
|
public function user()
|
|
|
|
{
|
2021-09-08 01:29:20 +02:00
|
|
|
return $this->belongsTo(User::class)->withTrashed();
|
2019-12-30 22:59:12 +01:00
|
|
|
}
|
2019-09-10 04:30:43 +02:00
|
|
|
|
2019-12-30 22:59:12 +01:00
|
|
|
public function clients()
|
|
|
|
{
|
|
|
|
return $this->hasMany(Client::class, 'id', 'group_settings_id');
|
|
|
|
}
|
2019-09-11 07:32:47 +02:00
|
|
|
|
2021-01-18 12:06:26 +01:00
|
|
|
public function documents()
|
|
|
|
{
|
|
|
|
return $this->morphMany(Document::class, 'documentable');
|
|
|
|
}
|
2022-06-21 11:57:17 +02:00
|
|
|
|
2023-01-29 09:56:13 +01:00
|
|
|
/**
|
|
|
|
* Retrieve the model for a bound value.
|
|
|
|
*
|
|
|
|
* @param mixed $value
|
|
|
|
* @param null $field
|
|
|
|
* @return Model|null
|
|
|
|
*/
|
|
|
|
public function resolveRouteBinding($value, $field = null)
|
|
|
|
{
|
|
|
|
if (is_numeric($value)) {
|
|
|
|
throw new ModelNotFoundException("Record with value {$value} not found");
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this
|
|
|
|
->withTrashed()
|
|
|
|
->company()
|
|
|
|
->where('id', $this->decodePrimaryKey($value))->firstOrFail();
|
|
|
|
}
|
2019-12-30 22:59:12 +01:00
|
|
|
}
|