invoiceninja/app/Models/GroupSetting.php

86 lines
1.9 KiB
PHP
Raw Normal View History

2019-09-10 12:30:43 +10:00
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
2019-09-10 12:30:43 +10:00
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
2023-01-29 09:21:40 +11:00
* @copyright Copyright (c) 2023. Invoice Ninja LLC (https://invoiceninja.com)
2019-09-10 12:30:43 +10:00
*
2021-06-16 16:58:16 +10:00
* @license https://www.elastic.co/licensing/elastic-license
2019-09-10 12:30:43 +10:00
*/
namespace App\Models;
use App\Utils\Traits\MakesHash;
2019-09-11 15:32:47 +10:00
use Illuminate\Database\Eloquent\Model;
2023-01-29 19:56:13 +11:00
use Illuminate\Database\Eloquent\ModelNotFoundException as ModelNotFoundException;
2023-02-16 12:36:09 +11:00
use Illuminate\Database\Eloquent\SoftDeletes;
2019-09-10 12:30:43 +10:00
class GroupSetting extends StaticModel
2019-09-10 12:30:43 +10:00
{
use MakesHash;
2020-02-27 10:32:44 +11:00
use SoftDeletes;
2019-09-10 12:30:43 +10:00
protected $casts = [
'settings' => 'object',
'updated_at' => 'timestamp',
'created_at' => 'timestamp',
'deleted_at' => 'timestamp',
2019-09-10 12:30:43 +10:00
];
2019-10-05 08:58:51 +10:00
protected $fillable = [
'name',
'settings',
2019-10-05 10:11:04 +10:00
];
2019-10-05 08:58:51 +10:00
protected $appends = [
'hashed_id',
];
public function getHashedIdAttribute()
{
return $this->encodePrimaryKey($this->id);
}
2020-07-23 13:55:11 +10:00
protected $touches = [];
public function company()
{
return $this->belongsTo(Company::class);
}
2019-09-10 12:30:43 +10:00
public function user()
{
return $this->belongsTo(User::class)->withTrashed();
}
2019-09-10 12:30:43 +10:00
public function clients()
{
return $this->hasMany(Client::class, 'id', 'group_settings_id');
}
2019-09-11 15:32:47 +10:00
2021-01-18 22:06:26 +11:00
public function documents()
{
return $this->morphMany(Document::class, 'documentable');
}
2023-01-29 19:56:13 +11: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();
}
}