API can deal with attachments for more models. #2828

This commit is contained in:
James Cole
2020-03-19 08:32:42 +01:00
parent 3246b7eb9f
commit 75afe35e98
21 changed files with 277 additions and 4 deletions

View File

@@ -134,6 +134,16 @@ class Account extends Model
throw new NotFoundHttpException;
}
/**
* @codeCoverageIgnore
* @return MorphMany
*/
public function attachments(): MorphMany
{
return $this->morphMany(Attachment::class, 'attachable');
}
/**
* @return HasMany
* @codeCoverageIgnore

View File

@@ -58,8 +58,6 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
* @SuppressWarnings (PHPMD.CouplingBetweenObjects)
* @property \Illuminate\Support\Carbon|null $deleted_at
* @property int $user_id
* @property bool $name_encrypted
* @property bool $match_encrypted
* @property-read \Illuminate\Database\Eloquent\Collection|Attachment[] $attachments
* @property-read \Illuminate\Database\Eloquent\Collection|TransactionJournal[] $transactionJournals
* @method static bool|null forceDelete()

View File

@@ -29,6 +29,7 @@ use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\MorphMany;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Database\Query\Builder;
use Illuminate\Support\Collection;
@@ -133,6 +134,16 @@ class Budget extends Model
return $this->hasMany(BudgetLimit::class);
}
/**
* @codeCoverageIgnore
* @return MorphMany
*/
public function attachments(): MorphMany
{
return $this->morphMany(Attachment::class, 'attachable');
}
/**
* @codeCoverageIgnore
* @return BelongsToMany

View File

@@ -30,6 +30,7 @@ use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\MorphMany;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Database\Query\Builder;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
@@ -47,7 +48,6 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
* @property Carbon $updated_at
* @property \Illuminate\Support\Carbon|null $deleted_at
* @property int $user_id
* @property bool $encrypted
* @property-read Collection|TransactionJournal[] $transactionJournals
* @property-read Collection|Transaction[] $transactions
* @method static bool|null forceDelete()
@@ -120,6 +120,16 @@ class Category extends Model
return $this->belongsToMany(TransactionJournal::class, 'category_transaction_journal', 'category_id');
}
/**
* @codeCoverageIgnore
* @return MorphMany
*/
public function attachments(): MorphMany
{
return $this->morphMany(Attachment::class, 'attachable');
}
/**
* @codeCoverageIgnore
* @return BelongsToMany

View File

@@ -49,7 +49,6 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
* @property int $account_id
* @property bool encrypted
* @property \Illuminate\Support\Carbon|null $deleted_at
* @property bool $encrypted
* @property-read Collection|Note[] $notes
* @property-read Collection|PiggyBankEvent[] $piggyBankEvents
* @property-read Collection|PiggyBankRepetition[] $piggyBankRepetitions
@@ -122,6 +121,15 @@ class PiggyBank extends Model
throw new NotFoundHttpException;
}
/**
* @codeCoverageIgnore
* @return MorphMany
*/
public function attachments(): MorphMany
{
return $this->morphMany(Attachment::class, 'attachable');
}
/**
* @codeCoverageIgnore
* @return BelongsTo

View File

@@ -130,6 +130,15 @@ class Tag extends Model
return $this->morphMany(Location::class, 'locatable');
}
/**
* @codeCoverageIgnore
* @return MorphMany
*/
public function attachments(): MorphMany
{
return $this->morphMany(Attachment::class, 'attachable');
}
/**
* @codeCoverageIgnore
* @return BelongsToMany