With the attach function, you can upload both the file and its cover image (if applicable).
Here are the arguments that the attach function accepts:
The first argument is the file that you want to upload (required).
The second argument is the cover image for the file (optional).
$file = $request->file('file');$cover = $request->file('cover');$upload->file->attach($file, $cover);// or (recommended)$upload->attachment('file')->attach($file, $cover);$upload->save();
If you provide a cover file when calling the attach function, the package will prioritize using your uploaded file as the cover instead of automatically generating one.
In this method, you can create and upload a file in one line of code. All you need to do is to pass the file and any required information to the create method of your model.
For example, if you have an Upload model that has an attachment named file, you can create and upload a file by writing the following code: