2019-09-12 03:28:41 +02:00
|
|
|
<?php
|
|
|
|
/**
|
2020-09-06 11:38:10 +02:00
|
|
|
* Invoice Ninja (https://invoiceninja.com).
|
2019-09-12 03:28:41 +02:00
|
|
|
*
|
|
|
|
* @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)
|
2019-09-12 03:28:41 +02:00
|
|
|
*
|
2021-06-16 08:58:16 +02:00
|
|
|
* @license https://www.elastic.co/licensing/elastic-license
|
2019-09-12 03:28:41 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
2023-02-20 08:46:26 +01:00
|
|
|
use App\Models\Traits\Excludable;
|
2023-02-22 07:37:16 +01:00
|
|
|
use App\Utils\Traits\MakesHash;
|
2019-09-12 03:28:41 +02:00
|
|
|
use Illuminate\Database\Eloquent\Model;
|
2023-01-22 06:34:47 +01:00
|
|
|
use Illuminate\Database\Eloquent\ModelNotFoundException as ModelNotFoundException;
|
2019-09-12 03:28:41 +02:00
|
|
|
|
2023-03-08 08:33:42 +01:00
|
|
|
/**
|
|
|
|
* App\Models\StaticModel
|
|
|
|
*
|
|
|
|
* @property-read mixed $id
|
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|StaticModel company()
|
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|StaticModel exclude($columns)
|
2023-08-03 06:30:14 +02:00
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|StaticModel newModelQuery()
|
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|StaticModel newQuery()
|
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|StaticModel query()
|
2023-07-24 10:57:02 +02:00
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|StaticModel find($value)
|
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|StaticModel with($value)
|
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|StaticModel withTrashed($value)
|
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|StaticModel findOrFail($value)
|
2023-03-08 08:33:42 +01:00
|
|
|
* @mixin \Eloquent
|
|
|
|
*/
|
2019-09-12 03:28:41 +02:00
|
|
|
class StaticModel extends Model
|
|
|
|
{
|
2023-01-22 06:34:47 +01:00
|
|
|
use MakesHash;
|
2023-02-20 08:46:26 +01:00
|
|
|
use Excludable;
|
2023-12-19 16:52:48 +01:00
|
|
|
|
2019-09-26 00:27:26 +02:00
|
|
|
protected $casts = [
|
|
|
|
'updated_at' => 'timestamp',
|
|
|
|
'created_at' => 'timestamp',
|
|
|
|
'deleted_at' => 'timestamp',
|
|
|
|
];
|
2020-09-06 11:38:10 +02:00
|
|
|
|
2019-12-30 22:59:12 +01:00
|
|
|
protected $dateFormat = 'Y-m-d H:i:s.u';
|
2019-09-27 06:31:13 +02:00
|
|
|
|
2019-09-12 03:28:41 +02:00
|
|
|
public function getIdAttribute()
|
|
|
|
{
|
2020-09-06 11:38:10 +02:00
|
|
|
return (string) $this->attributes['id'];
|
2019-09-12 03:28:41 +02:00
|
|
|
}
|
|
|
|
|
2019-11-27 10:47:59 +01:00
|
|
|
/*
|
|
|
|
V2 type of scope
|
|
|
|
*/
|
|
|
|
public function scopeCompany($query)
|
|
|
|
{
|
2023-04-27 07:09:55 +02:00
|
|
|
/** @var \App\Models\User $user */
|
|
|
|
$user = auth()->user();
|
|
|
|
|
|
|
|
$query->where('company_id', $user->companyId());
|
2020-09-06 11:38:10 +02:00
|
|
|
|
2019-11-27 10:47:59 +01:00
|
|
|
return $query;
|
|
|
|
}
|
2023-01-22 06:34:47 +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
|
|
|
|
->where('id', $this->decodePrimaryKey($value))->firstOrFail();
|
|
|
|
}
|
2019-09-12 03:28:41 +02:00
|
|
|
}
|