Files
firefly-iii/app/Models/LinkType.php

112 lines
4.2 KiB
PHP
Raw Normal View History

2017-08-20 12:41:31 +02:00
<?php
/**
* LinkType.php
2020-02-16 13:55:32 +01:00
* Copyright (c) 2019 james@firefly-iii.org
2017-08-20 12:41:31 +02:00
*
* This file is part of Firefly III (https://github.com/firefly-iii).
2017-10-21 08:40:00 +02:00
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
2017-10-21 08:40:00 +02:00
*
* This program is distributed in the hope that it will be useful,
2017-10-21 08:40:00 +02:00
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
2017-10-21 08:40:00 +02:00
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
2017-08-20 12:41:31 +02:00
*/
declare(strict_types=1);
namespace FireflyIII\Models;
2018-06-28 17:02:13 +02:00
use Carbon\Carbon;
use Eloquent;
use Illuminate\Database\Eloquent\Collection;
2017-08-20 12:41:31 +02:00
use Illuminate\Database\Eloquent\Model;
2018-08-04 17:30:06 +02:00
use Illuminate\Database\Eloquent\Relations\HasMany;
2018-06-28 22:14:50 +02:00
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Database\Query\Builder;
2017-08-23 21:21:42 +02:00
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
2017-08-20 12:41:31 +02:00
/**
2019-03-05 17:26:49 +01:00
* FireflyIII\Models\LinkType
*
2021-05-24 08:50:17 +02:00
* @property int $id
* @property \Illuminate\Support\Carbon|null $created_at
* @property \Illuminate\Support\Carbon|null $updated_at
* @property \Illuminate\Support\Carbon|null $deleted_at
* @property string $name
* @property string $outward
* @property string $inward
* @property int $journalCount
* @property bool $editable
* @property-read Collection|TransactionJournalLink[] $transactionJournalLinks
* @property-read int|null $transaction_journal_links_count
* @method static \Illuminate\Database\Eloquent\Builder|LinkType newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|LinkType newQuery()
* @method static Builder|LinkType onlyTrashed()
* @method static \Illuminate\Database\Eloquent\Builder|LinkType query()
* @method static \Illuminate\Database\Eloquent\Builder|LinkType whereCreatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|LinkType whereDeletedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|LinkType whereEditable($value)
* @method static \Illuminate\Database\Eloquent\Builder|LinkType whereId($value)
* @method static \Illuminate\Database\Eloquent\Builder|LinkType whereInward($value)
* @method static \Illuminate\Database\Eloquent\Builder|LinkType whereName($value)
* @method static \Illuminate\Database\Eloquent\Builder|LinkType whereOutward($value)
* @method static \Illuminate\Database\Eloquent\Builder|LinkType whereUpdatedAt($value)
* @method static Builder|LinkType withTrashed()
* @method static Builder|LinkType withoutTrashed()
* @mixin Eloquent
2017-08-20 12:41:31 +02:00
*/
class LinkType extends Model
{
2018-06-28 22:14:50 +02:00
use SoftDeletes;
2017-08-20 12:41:31 +02:00
/**
* The attributes that should be casted to native types.
*
* @var array
*/
protected $casts
= [
2017-11-03 16:04:17 +01:00
'created_at' => 'datetime',
'updated_at' => 'datetime',
'deleted_at' => 'datetime',
2017-08-20 12:41:31 +02:00
'editable' => 'boolean',
];
2018-08-04 17:30:06 +02:00
/** @var array Fields that can be filled */
protected $fillable = ['name', 'inward', 'outward', 'editable'];
2017-08-23 21:21:42 +02:00
/**
2018-08-04 17:30:06 +02:00
* Route binder. Converts the key in the URL to the specified object (or throw 404).
*
2021-04-07 07:53:05 +02:00
* @param string $value
2017-08-23 21:21:42 +02:00
*
* @throws NotFoundHttpException
* @return LinkType
2017-11-15 12:25:49 +01:00
*
2017-08-23 21:21:42 +02:00
*/
2018-02-09 19:24:15 +01:00
public static function routeBinder(string $value): LinkType
2017-08-23 21:21:42 +02:00
{
if (auth()->check()) {
$linkTypeId = (int) $value;
$linkType = self::find($linkTypeId);
if (null !== $linkType) {
return $linkType;
2017-08-23 21:21:42 +02:00
}
}
throw new NotFoundHttpException;
}
2017-12-17 14:30:53 +01:00
/**
* @codeCoverageIgnore
2018-08-04 17:30:06 +02:00
* @return HasMany
2017-12-17 14:30:53 +01:00
*/
2018-08-04 17:30:06 +02:00
public function transactionJournalLinks(): HasMany
2017-08-23 21:21:42 +02:00
{
return $this->hasMany(TransactionJournalLink::class);
}
2017-08-31 06:47:18 +02:00
}