Larupload
  • 🏁Getting Started
    • Introduction
    • Installation
    • Laravel Nova integration
    • Support Us
    • License
  • 🚀Basic Usage
    • Database Preparation
    • Model Preparation
    • Upload
  • ⚙️Advanced Usage
    • Concepts
    • Configuration
      • Disk
      • Local Disk
      • Mode
      • SecureIds
      • With Meta
      • Camel Case Response
      • Hide Table Columns
      • Naming Method
      • Lang
      • Image Processing Library
      • Generate Cover
      • Cover Style
      • Dominant Color
      • Dominant Color Quality
      • Keep Old Files
      • Preserve Files
      • Store Original File Name
      • Optimize Image
      • FFMpeg
        • FFMpeg Binaries
        • FFMpeg Threads
        • FFMpeg Capture Frame
        • FFMpeg Queue
        • FFMpeg Max Queue Number
        • FFMpeg Timeout
        • FFMPEG Log Channel
    • Attachment
      • Disk
      • With Meta
      • Naming Method
      • Lang
      • Image Processing Library
      • Generate Cover
      • Cover Style
      • Dominant Color
      • Dominant Color Quality
      • Keep Old Files
      • Preserve Files
      • Store Original File Name
      • SecureIds Method
      • Optimize Image
      • Media Styles
      • Complete Example
    • Migrations
      • Heavy Columns
      • Light Columns
      • Add Original File Name to Existing Tables
  • Upload
  • Delete
  • Cover
    • Upload Cover
    • Update Cover
    • Delete Cover
  • Download
    • Generate Download Link
      • Generate URL for particular style
      • Generate URL for all styles
    • Generate Download Response
  • Meta
  • Get Attachments
  • API Resources
  • Image Optimization
  • SecureIds
  • Queue FFMpeg Processes
    • Job Completion Event
    • FFMpeg Queue Relationships
  • 🧱Standalone Uploader
    • Introduction
    • Upload
    • Delete
    • Cover
      • Update Cover
      • Delete Cover
    • Customization
  • ⚪OTHER
    • Migration
Powered by GitBook
On this page
Edit on GitHub

Upload

There are three ways to upload files using Larupload:

  • Upload by mutator

  • Upload by the attach function

  • Upload using the create method of the model

This is the easiest way to upload a file. You can upload a file by assigning the file to a property of your model.

It is advising that when uploading a file using Larupload, the corresponding property must be defined in the attachments method of the model.

$upload = new Upload;
$upload->file = $request->file('file');
$upload->save();

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:

$upload = Upload::create([
    'file' => $request->file('file')
]);

PreviousAdd Original File Name to Existing TablesNextDelete

Last updated 10 months ago