. */ declare(strict_types=1); namespace FireflyIII\Models; use FireflyIII\User; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsTo; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; /** * Class ExportJob. * * @property User $user * @property string $key * @property int $user_id * @property string status * @property int id */ class ExportJob extends Model { /** * The attributes that should be casted to native types. * * @var array */ protected $casts = [ 'created_at' => 'datetime', 'updated_at' => 'datetime', ]; /** * Route binder. Converts the key in the URL to the specified object (or throw 404). * * @param string $value * * @return ExportJob * * @throws NotFoundHttpException */ public static function routeBinder(string $value): ExportJob { if (auth()->check()) { $key = trim($value); /** @var User $user */ $user = auth()->user(); /** @var ExportJob $exportJob */ $exportJob = $user->exportJobs()->where('key', $key)->first(); if (null !== $exportJob) { return $exportJob; } } throw new NotFoundHttpException; } /** * Change the status of this export job. * * @param $status * * @deprecated * @codeCoverageIgnore */ public function change($status): void { $this->status = $status; $this->save(); } /** * Returns the user this objects belongs to. * * * @return BelongsTo * @codeCoverageIgnore */ public function user(): BelongsTo { return $this->belongsTo(User::class); } }