$exporter * @property int $processed_rows * @property int $total_rows * @property int $successful_rows * @property-read Authenticatable $user */ class Export extends Model { use Prunable; protected $casts = [ 'completed_at' => 'timestamp', 'processed_rows' => 'integer', 'total_rows' => 'integer', 'successful_rows' => 'integer', ]; protected $guarded = []; protected static bool $hasPolymorphicUserRelationship = false; public function user(): BelongsTo { if (static::hasPolymorphicUserRelationship()) { return $this->morphTo(); } /** @var ?Authenticatable $authenticatable */ $authenticatable = app(Authenticatable::class); if ($authenticatable) { /** @phpstan-ignore-next-line */ return $this->belongsTo($authenticatable::class); } if (! class_exists(User::class)) { throw new Exception('No [App\\Models\\User] model found. Please bind an authenticatable model to the [Illuminate\\Contracts\\Auth\\Authenticatable] interface in a service provider\'s [register()] method.'); } /** @phpstan-ignore-next-line */ return $this->belongsTo(User::class); } /** * @param array $columnMap * @param array $options */ public function getExporter( array $columnMap, array $options, ): Exporter { return app($this->exporter, [ 'export' => $this, 'columnMap' => $columnMap, 'options' => $options, ]); } public function getFailedRowsCount(): int { return $this->total_rows - $this->successful_rows; } public static function polymorphicUserRelationship(bool $condition = true): void { static::$hasPolymorphicUserRelationship = $condition; } public static function hasPolymorphicUserRelationship(): bool { return static::$hasPolymorphicUserRelationship; } public function getFileDisk(): Filesystem { return Storage::disk($this->file_disk); } public function getFileDirectory(): string { return 'filament_exports' . DIRECTORY_SEPARATOR . $this->getKey(); } public function deleteFileDirectory(): void { $disk = $this->getFileDisk(); $directory = $this->getFileDirectory(); if ($disk->directoryExists($directory)) { $disk->deleteDirectory($directory); } } }