Inputs and outputs
Choose a DWG source
All operations accept an uploaded file (UploadedFile), a local absolute path, or DWG bytes wrapped in DwgBinary. convert(), extract(), and read() work on a temporary copy. Dwg::version() reads the source header directly. All leave the source unchanged.
Uploaded files
Pass a valid Laravel UploadedFile directly.
use Mattmy\DwgConverter\Facades\Dwg;
$result = Dwg::toDxf($request->file('drawing'))->convert();Validate that the field contains one file before calling the package. $request->file('drawing') can return null for an empty field. The package rejects invalid or incomplete uploads before starting an external tool.
Local absolute paths
A plain string always means a local absolute path.
$result = Dwg::toDxf(storage_path('app/private/floor-plan.dwg'))->convert();Relative paths, URLs, stream wrappers, Storage-relative paths, and Windows UNC paths are not accepted.
DWG bytes
Wrap DWG bytes in DwgBinary so the package can distinguish them from a path.
use Mattmy\DwgConverter\DwgBinary;
$result = Dwg::toDxf(DwgBinary::from($bytes))->convert();One-time output
Conversions and thumbnail extraction return DwgOutput.
The result holds temporary files, so keep it in the same process. Cloning, serializing, or unserializing it throws LogicException; the original result stays unchanged. For a queue job, make the source file available to the worker and run the conversion inside the job.
$extension = $result->extension();
$mimeType = $result->mimeType();You can read this metadata more than once. Use storeAs() to stream the file to Laravel Storage.
$path = $result->storeAs('drawings', 'floor-plan.dxf', 's3');Use output() to read the full file into PHP memory.
$bytes = $result->output();For storeAs(), pass a disk-relative directory such as drawings/2026, or an empty string for the disk root. Use / between directory names and avoid . and .. segments. Omit disk to use Laravel's default disk. The method returns the stored path relative to that disk.
Its optional name must be a filename without a directory path. The package keeps that name and adds the output extension if needed, or normalizes its letter case if it already matches. For WebP output, plan.WEBP becomes plan.webp and plan.png becomes plan.png.webp. Without a name, local files and uploads use their filename without the extension. An unsafe or missing source name, including DwgBinary, falls back to converted-{16 lowercase hex}.
For each DwgOutput, choose either storeAs() or output() and call it once. A second call throws LogicException even if the first failed. Rerun the original operation to get a fresh result before retrying. The package attempts to clean up temporary files after the call or when an unused result is destroyed.
If temporary files remain, see cleanup warnings.
Layer query results
layers()->read() returns a regular Collection<int, DwgLayer> that you can filter and count repeatedly, without one-time output restrictions. See Reading layer data for examples.
Entity queries
entities()->read() returns DwgEntityQueryResult, with a reusable DwgEntityCollection in entities. See Reading stored entities for examples.
Drawing information
version() returns a DwgFileVersion immediately. info()->read() returns a DwgInfo after querying the drawing. Both results are reusable. See Reading drawing information.