Skip to content

Instantly share code, notes, and snippets.

@garyconstable
Last active September 4, 2019 11:01

Revisions

  1. garyconstable revised this gist Sep 4, 2019. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion upload.php
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,6 @@
    public function store(Request $request)
    <?php

    function store(Request $request)
    {
    $this->validateImage($request);

  2. garyconstable created this gist Sep 4, 2019.
    32 changes: 32 additions & 0 deletions upload.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,32 @@
    public function store(Request $request)
    {
    $this->validateImage($request);

    $image = new Image();

    $file = $request->file('file');

    $image->original_file_name = 'original.'.$file->extension();
    $image->thumbnail_file_name = 'thumbnail.'.$file->extension();

    $image->save();

    $disk = Image::disk();

    // Upload the original image...
    $disk->putFileAs(
    $image->getBasePath(),
    $file,
    $image->original_file_name
    );

    // Create and upload the thumbnail...
    $disk->put(
    $image->thumbnail_file_path,
    value(function () use ($file, $image, $disk) {
    return Manipulator::make($file)->fit(300, 300)->stream();
    })
    );

    return new ImageResource($image);
    }