. */ declare(strict_types=1); namespace FireflyIII\Models; use Carbon\Carbon; use FireflyIII\User; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\Relations\MorphMany; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; /** * Class ImportJob. * * @property array $transactions * @property array $configuration * @property User $user * @property int $user_id * @property string $status * @property string $stage * @property string $key * @property string $provider * @property string $file_type * @property int $tag_id * @property Tag $tag * @property array $errors * @property array extended_status * @property int id * @property Carbon $created_at * @property Carbon $updated_at * @property int $id * @property array|null $extended_status * @property-read \Illuminate\Database\Eloquent\Collection|\FireflyIII\Models\Attachment[] $attachments * @method static \Illuminate\Database\Eloquent\Builder|\FireflyIII\Models\ImportJob newModelQuery() * @method static \Illuminate\Database\Eloquent\Builder|\FireflyIII\Models\ImportJob newQuery() * @method static \Illuminate\Database\Eloquent\Builder|\FireflyIII\Models\ImportJob query() * @method static \Illuminate\Database\Eloquent\Builder|\FireflyIII\Models\ImportJob whereConfiguration($value) * @method static \Illuminate\Database\Eloquent\Builder|\FireflyIII\Models\ImportJob whereCreatedAt($value) * @method static \Illuminate\Database\Eloquent\Builder|\FireflyIII\Models\ImportJob whereErrors($value) * @method static \Illuminate\Database\Eloquent\Builder|\FireflyIII\Models\ImportJob whereExtendedStatus($value) * @method static \Illuminate\Database\Eloquent\Builder|\FireflyIII\Models\ImportJob whereFileType($value) * @method static \Illuminate\Database\Eloquent\Builder|\FireflyIII\Models\ImportJob whereId($value) * @method static \Illuminate\Database\Eloquent\Builder|\FireflyIII\Models\ImportJob whereKey($value) * @method static \Illuminate\Database\Eloquent\Builder|\FireflyIII\Models\ImportJob whereProvider($value) * @method static \Illuminate\Database\Eloquent\Builder|\FireflyIII\Models\ImportJob whereStage($value) * @method static \Illuminate\Database\Eloquent\Builder|\FireflyIII\Models\ImportJob whereStatus($value) * @method static \Illuminate\Database\Eloquent\Builder|\FireflyIII\Models\ImportJob whereTagId($value) * @method static \Illuminate\Database\Eloquent\Builder|\FireflyIII\Models\ImportJob whereTransactions($value) * @method static \Illuminate\Database\Eloquent\Builder|\FireflyIII\Models\ImportJob whereUpdatedAt($value) * @method static \Illuminate\Database\Eloquent\Builder|\FireflyIII\Models\ImportJob whereUserId($value) * @mixin \Eloquent */ class ImportJob extends Model { /** * The attributes that should be casted to native types. * * @var array */ protected $casts = [ 'user_id' => 'int', 'created_at' => 'datetime', 'updated_at' => 'datetime', 'configuration' => 'array', 'extended_status' => 'array', 'transactions' => 'array', 'errors' => 'array', ]; /** @var array Fields that can be filled */ protected $fillable = ['key', 'user_id', 'file_type', 'provider', 'status', 'stage', 'configuration', 'extended_status', 'transactions', 'errors']; /** * Route binder. Converts the key in the URL to the specified object (or throw 404). * * @param $value * * @return mixed * * @throws NotFoundHttpException */ public static function routeBinder(string $value): ImportJob { if (auth()->check()) { $key = trim($value); /** @var User $user */ $user = auth()->user(); /** @var ImportJob $importJob */ $importJob = $user->importJobs()->where('key', $key)->first(); if (null !== $importJob) { return $importJob; } } throw new NotFoundHttpException; } /** * @codeCoverageIgnore * @return MorphMany */ public function attachments(): MorphMany { return $this->morphMany(Attachment::class, 'attachable'); } /** * @codeCoverageIgnore * @return BelongsTo */ public function tag(): BelongsTo { return $this->belongsTo(Tag::class); } /** * @codeCoverageIgnore * @return BelongsTo */ public function user(): BelongsTo { return $this->belongsTo(User::class); } }