From 278b52979212851c6c3abe5c9b724ba83355cb5c Mon Sep 17 00:00:00 2001 From: Seth Sharp Date: Mon, 5 Feb 2024 12:53:41 +1000 Subject: [PATCH] wip file upload --- app/Domain/File/Actions/StoreFileAction.php | 11 +- app/Domain/File/Models/File.php | 1 + .../Dashboard/Files/CreateFileController.php | 16 + .../Dashboard/Files/StoreFileController.php | 5 +- .../Dashboard/StoreFileController.php | 22 - .../Dashboard/Files/StoreFileRequest.php | 19 + composer.json | 8 +- composer.lock | 397 ++++++++++++++---- .../js/Components/Inputs/ImageUpload.vue | 52 +++ resources/js/Pages/Dashboard/Files/Create.vue | 41 ++ routes/blog.php | 5 +- 11 files changed, 458 insertions(+), 119 deletions(-) create mode 100644 app/Http/Controllers/Dashboard/Files/CreateFileController.php delete mode 100644 app/Http/Controllers/Dashboard/StoreFileController.php create mode 100644 app/Http/Requests/Dashboard/Files/StoreFileRequest.php create mode 100644 resources/js/Components/Inputs/ImageUpload.vue create mode 100644 resources/js/Pages/Dashboard/Files/Create.vue diff --git a/app/Domain/File/Actions/StoreFileAction.php b/app/Domain/File/Actions/StoreFileAction.php index b1e73787..ae313c48 100644 --- a/app/Domain/File/Actions/StoreFileAction.php +++ b/app/Domain/File/Actions/StoreFileAction.php @@ -17,17 +17,16 @@ public function __invoke(UploadedFile $file): File $dir = app()->environment('local') ? 'testing/' - : 'production'; + : 'production/'; $path = $file->hashName(path: $dir . 'categories'); - Storage::disk(config('filesystems.default')) - ->put($path, $img, 'public'); + Storage::disk('s3') + ->put($path, $img, 'public-read'); return File::create([ - 'path' => app()->environment('local') - ? $path - : Storage::url($path) + 'blog_id' => 1, + 'path' => Storage::disk('s3')->url($path), ]); } } diff --git a/app/Domain/File/Models/File.php b/app/Domain/File/Models/File.php index 6038317a..6df2a178 100644 --- a/app/Domain/File/Models/File.php +++ b/app/Domain/File/Models/File.php @@ -6,4 +6,5 @@ class File extends Model { + protected $guarded = []; } diff --git a/app/Http/Controllers/Dashboard/Files/CreateFileController.php b/app/Http/Controllers/Dashboard/Files/CreateFileController.php new file mode 100644 index 00000000..c4d98f83 --- /dev/null +++ b/app/Http/Controllers/Dashboard/Files/CreateFileController.php @@ -0,0 +1,16 @@ +file('file')); + dd($file); return [ 'url' => 'some-url-to-the-image' ]; diff --git a/app/Http/Controllers/Dashboard/StoreFileController.php b/app/Http/Controllers/Dashboard/StoreFileController.php deleted file mode 100644 index 6b74f428..00000000 --- a/app/Http/Controllers/Dashboard/StoreFileController.php +++ /dev/null @@ -1,22 +0,0 @@ -input('is_draft'); - - return redirect() - ->route('dashboard.blogs.index') - ->with('success', $blog->title . ' successfully ' . ($drafted ? 'drafted' : 'published')); - } -} diff --git a/app/Http/Requests/Dashboard/Files/StoreFileRequest.php b/app/Http/Requests/Dashboard/Files/StoreFileRequest.php new file mode 100644 index 00000000..fc1aafc9 --- /dev/null +++ b/app/Http/Requests/Dashboard/Files/StoreFileRequest.php @@ -0,0 +1,19 @@ + 'required|image|max:2000', + 'description' => ['min:5'] + ]; + } +} diff --git a/composer.json b/composer.json index 78354789..dc9106e1 100644 --- a/composer.json +++ b/composer.json @@ -9,18 +9,18 @@ "license": "MIT", "require": { "php": "^8.1", + "aws/aws-sdk-php": "^3.298", "codinglabsau/laravel-roles": "^2.4", "codinglabsau/php-styles": "dev-main", "guzzlehttp/guzzle": "^7.2", "inertiajs/inertia-laravel": "^0.6.8", - "intervention/image": "^3.3", + "intervention/image": "^2.7", "laravel/framework": "^9.19", "laravel/sanctum": "^3.2", "laravel/tinker": "^2.7", + "league/flysystem-aws-s3-v3": "^3.0", "livewire/livewire": "^2.12", - "tightenco/ziggy": "^1.0", - "aws/aws-sdk-php": "^3.288", - "league/flysystem-aws-s3-v3": "^3.0" + "tightenco/ziggy": "^1.0" }, "require-dev": { "fakerphp/faker": "^1.9.1", diff --git a/composer.lock b/composer.lock index 7994b476..824ed304 100644 --- a/composer.lock +++ b/composer.lock @@ -4,8 +4,157 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "f98af94a3bba4d79c71f2d1bc7091c09", + "content-hash": "d875f082097cb7ef44ff785bd2d3aa88", "packages": [ + { + "name": "aws/aws-crt-php", + "version": "v1.2.4", + "source": { + "type": "git", + "url": "https://github.com/awslabs/aws-crt-php.git", + "reference": "eb0c6e4e142224a10b08f49ebf87f32611d162b2" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/awslabs/aws-crt-php/zipball/eb0c6e4e142224a10b08f49ebf87f32611d162b2", + "reference": "eb0c6e4e142224a10b08f49ebf87f32611d162b2", + "shasum": "" + }, + "require": { + "php": ">=5.5" + }, + "require-dev": { + "phpunit/phpunit": "^4.8.35||^5.6.3||^9.5", + "yoast/phpunit-polyfills": "^1.0" + }, + "suggest": { + "ext-awscrt": "Make sure you install awscrt native extension to use any of the functionality." + }, + "type": "library", + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "Apache-2.0" + ], + "authors": [ + { + "name": "AWS SDK Common Runtime Team", + "email": "aws-sdk-common-runtime@amazon.com" + } + ], + "description": "AWS Common Runtime for PHP", + "homepage": "https://github.com/awslabs/aws-crt-php", + "keywords": [ + "amazon", + "aws", + "crt", + "sdk" + ], + "support": { + "issues": "https://github.com/awslabs/aws-crt-php/issues", + "source": "https://github.com/awslabs/aws-crt-php/tree/v1.2.4" + }, + "time": "2023-11-08T00:42:13+00:00" + }, + { + "name": "aws/aws-sdk-php", + "version": "3.298.2", + "source": { + "type": "git", + "url": "https://github.com/aws/aws-sdk-php.git", + "reference": "626f731c38e06ea483025334512f4c2afea1739d" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/aws/aws-sdk-php/zipball/626f731c38e06ea483025334512f4c2afea1739d", + "reference": "626f731c38e06ea483025334512f4c2afea1739d", + "shasum": "" + }, + "require": { + "aws/aws-crt-php": "^1.2.3", + "ext-json": "*", + "ext-pcre": "*", + "ext-simplexml": "*", + "guzzlehttp/guzzle": "^6.5.8 || ^7.4.5", + "guzzlehttp/promises": "^1.4.0 || ^2.0", + "guzzlehttp/psr7": "^1.9.1 || ^2.4.5", + "mtdowling/jmespath.php": "^2.6", + "php": ">=7.2.5", + "psr/http-message": "^1.0 || ^2.0" + }, + "require-dev": { + "andrewsville/php-token-reflection": "^1.4", + "aws/aws-php-sns-message-validator": "~1.0", + "behat/behat": "~3.0", + "composer/composer": "^1.10.22", + "dms/phpunit-arraysubset-asserts": "^0.4.0", + "doctrine/cache": "~1.4", + "ext-dom": "*", + "ext-openssl": "*", + "ext-pcntl": "*", + "ext-sockets": "*", + "nette/neon": "^2.3", + "paragonie/random_compat": ">= 2", + "phpunit/phpunit": "^5.6.3 || ^8.5 || ^9.5", + "psr/cache": "^1.0", + "psr/simple-cache": "^1.0", + "sebastian/comparator": "^1.2.3 || ^4.0", + "yoast/phpunit-polyfills": "^1.0" + }, + "suggest": { + "aws/aws-php-sns-message-validator": "To validate incoming SNS notifications", + "doctrine/cache": "To use the DoctrineCacheAdapter", + "ext-curl": "To send requests using cURL", + "ext-openssl": "Allows working with CloudFront private distributions and verifying received SNS messages", + "ext-sockets": "To use client-side monitoring" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.0-dev" + } + }, + "autoload": { + "files": [ + "src/functions.php" + ], + "psr-4": { + "Aws\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "Apache-2.0" + ], + "authors": [ + { + "name": "Amazon Web Services", + "homepage": "http://aws.amazon.com" + } + ], + "description": "AWS SDK for PHP - Use Amazon Web Services in your PHP project", + "homepage": "http://aws.amazon.com/sdkforphp", + "keywords": [ + "amazon", + "aws", + "cloud", + "dynamodb", + "ec2", + "glacier", + "s3", + "sdk" + ], + "support": { + "forum": "https://forums.aws.amazon.com/forum.jspa?forumID=80", + "issues": "https://github.com/aws/aws-sdk-php/issues", + "source": "https://github.com/aws/aws-sdk-php/tree/3.298.2" + }, + "time": "2024-02-02T19:05:34+00:00" + }, { "name": "brick/math", "version": "0.11.0", @@ -1519,102 +1668,51 @@ ], "time": "2023-10-27T10:59:02+00:00" }, - { - "name": "intervention/gif", - "version": "4.0.1", - "source": { - "type": "git", - "url": "https://github.com/Intervention/gif.git", - "reference": "3d4fa6e5eed87f344ada9c0beb410d68e9f274ae" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/Intervention/gif/zipball/3d4fa6e5eed87f344ada9c0beb410d68e9f274ae", - "reference": "3d4fa6e5eed87f344ada9c0beb410d68e9f274ae", - "shasum": "" - }, - "require": { - "php": "^8.1" - }, - "require-dev": { - "phpstan/phpstan": "^1", - "phpunit/phpunit": "^9", - "squizlabs/php_codesniffer": "^3.8" - }, - "type": "library", - "autoload": { - "psr-4": { - "Intervention\\Gif\\": "src" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Oliver Vogel", - "email": "oliver@intervention.io", - "homepage": "https://intervention.io/" - } - ], - "description": "Native PHP GIF Encoder/Decoder", - "homepage": "https://github.com/intervention/gif", - "keywords": [ - "animation", - "gd", - "gif", - "image" - ], - "support": { - "issues": "https://github.com/Intervention/gif/issues", - "source": "https://github.com/Intervention/gif/tree/4.0.1" - }, - "funding": [ - { - "url": "https://paypal.me/interventionio", - "type": "custom" - }, - { - "url": "https://github.com/Intervention", - "type": "github" - } - ], - "time": "2024-01-27T08:01:45+00:00" - }, { "name": "intervention/image", - "version": "3.3.3", + "version": "2.7.2", "source": { "type": "git", "url": "https://github.com/Intervention/image.git", - "reference": "ad8058f5be94110d72d44958a5e5f4a0705c7471" + "reference": "04be355f8d6734c826045d02a1079ad658322dad" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/Intervention/image/zipball/ad8058f5be94110d72d44958a5e5f4a0705c7471", - "reference": "ad8058f5be94110d72d44958a5e5f4a0705c7471", + "url": "https://api.github.com/repos/Intervention/image/zipball/04be355f8d6734c826045d02a1079ad658322dad", + "reference": "04be355f8d6734c826045d02a1079ad658322dad", "shasum": "" }, "require": { - "ext-mbstring": "*", - "intervention/gif": "^4.0.1", - "php": "^8.1" + "ext-fileinfo": "*", + "guzzlehttp/psr7": "~1.1 || ^2.0", + "php": ">=5.4.0" }, "require-dev": { - "mockery/mockery": "^1.6", - "phpstan/phpstan": "^1", - "phpunit/phpunit": "^9", - "slevomat/coding-standard": "~8.0", - "squizlabs/php_codesniffer": "^3.8" + "mockery/mockery": "~0.9.2", + "phpunit/phpunit": "^4.8 || ^5.7 || ^7.5.15" }, "suggest": { - "ext-exif": "Recommended to be able to read EXIF data properly." + "ext-gd": "to use GD library based image processing.", + "ext-imagick": "to use Imagick based image processing.", + "intervention/imagecache": "Caching extension for the Intervention Image library" }, "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.4-dev" + }, + "laravel": { + "providers": [ + "Intervention\\Image\\ImageServiceProvider" + ], + "aliases": { + "Image": "Intervention\\Image\\Facades\\Image" + } + } + }, "autoload": { "psr-4": { - "Intervention\\Image\\": "src" + "Intervention\\Image\\": "src/Intervention/Image" } }, "notification-url": "https://packagist.org/downloads/", @@ -1628,19 +1726,19 @@ "homepage": "https://intervention.io/" } ], - "description": "PHP image manipulation", - "homepage": "https://image.intervention.io/", + "description": "Image handling and manipulation library with support for Laravel integration", + "homepage": "http://image.intervention.io/", "keywords": [ "gd", "image", "imagick", - "resize", + "laravel", "thumbnail", "watermark" ], "support": { "issues": "https://github.com/Intervention/image/issues", - "source": "https://github.com/Intervention/image/tree/3.3.3" + "source": "https://github.com/Intervention/image/tree/2.7.2" }, "funding": [ { @@ -1652,7 +1750,7 @@ "type": "github" } ], - "time": "2024-02-02T15:08:10+00:00" + "time": "2022-05-21T17:30:32+00:00" }, { "name": "laravel/framework", @@ -2322,6 +2420,71 @@ ], "time": "2023-12-04T10:16:17+00:00" }, + { + "name": "league/flysystem-aws-s3-v3", + "version": "3.24.0", + "source": { + "type": "git", + "url": "https://github.com/thephpleague/flysystem-aws-s3-v3.git", + "reference": "809474e37b7fb1d1f8bcc0f8a98bc1cae99aa513" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/thephpleague/flysystem-aws-s3-v3/zipball/809474e37b7fb1d1f8bcc0f8a98bc1cae99aa513", + "reference": "809474e37b7fb1d1f8bcc0f8a98bc1cae99aa513", + "shasum": "" + }, + "require": { + "aws/aws-sdk-php": "^3.295.10", + "league/flysystem": "^3.10.0", + "league/mime-type-detection": "^1.0.0", + "php": "^8.0.2" + }, + "conflict": { + "guzzlehttp/guzzle": "<7.0", + "guzzlehttp/ringphp": "<1.1.1" + }, + "type": "library", + "autoload": { + "psr-4": { + "League\\Flysystem\\AwsS3V3\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Frank de Jonge", + "email": "info@frankdejonge.nl" + } + ], + "description": "AWS S3 filesystem adapter for Flysystem.", + "keywords": [ + "Flysystem", + "aws", + "file", + "files", + "filesystem", + "s3", + "storage" + ], + "support": { + "source": "https://github.com/thephpleague/flysystem-aws-s3-v3/tree/3.24.0" + }, + "funding": [ + { + "url": "https://ecologi.com/frankdejonge", + "type": "custom" + }, + { + "url": "https://github.com/frankdejonge", + "type": "github" + } + ], + "time": "2024-01-26T18:43:21+00:00" + }, { "name": "league/flysystem-local", "version": "3.23.0", @@ -2613,6 +2776,72 @@ ], "time": "2023-10-27T15:25:26+00:00" }, + { + "name": "mtdowling/jmespath.php", + "version": "2.7.0", + "source": { + "type": "git", + "url": "https://github.com/jmespath/jmespath.php.git", + "reference": "bbb69a935c2cbb0c03d7f481a238027430f6440b" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/jmespath/jmespath.php/zipball/bbb69a935c2cbb0c03d7f481a238027430f6440b", + "reference": "bbb69a935c2cbb0c03d7f481a238027430f6440b", + "shasum": "" + }, + "require": { + "php": "^7.2.5 || ^8.0", + "symfony/polyfill-mbstring": "^1.17" + }, + "require-dev": { + "composer/xdebug-handler": "^3.0.3", + "phpunit/phpunit": "^8.5.33" + }, + "bin": [ + "bin/jp.php" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.7-dev" + } + }, + "autoload": { + "files": [ + "src/JmesPath.php" + ], + "psr-4": { + "JmesPath\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Graham Campbell", + "email": "hello@gjcampbell.co.uk", + "homepage": "https://github.com/GrahamCampbell" + }, + { + "name": "Michael Dowling", + "email": "mtdowling@gmail.com", + "homepage": "https://github.com/mtdowling" + } + ], + "description": "Declaratively specify how to extract elements from a JSON document", + "keywords": [ + "json", + "jsonpath" + ], + "support": { + "issues": "https://github.com/jmespath/jmespath.php/issues", + "source": "https://github.com/jmespath/jmespath.php/tree/2.7.0" + }, + "time": "2023-08-25T10:54:48+00:00" + }, { "name": "nesbot/carbon", "version": "2.72.2", @@ -9282,5 +9511,5 @@ "php": "^8.1" }, "platform-dev": [], - "plugin-api-version": "2.6.0" + "plugin-api-version": "2.3.0" } diff --git a/resources/js/Components/Inputs/ImageUpload.vue b/resources/js/Components/Inputs/ImageUpload.vue new file mode 100644 index 00000000..f436c3f5 --- /dev/null +++ b/resources/js/Components/Inputs/ImageUpload.vue @@ -0,0 +1,52 @@ + + + diff --git a/resources/js/Pages/Dashboard/Files/Create.vue b/resources/js/Pages/Dashboard/Files/Create.vue new file mode 100644 index 00000000..875362cd --- /dev/null +++ b/resources/js/Pages/Dashboard/Files/Create.vue @@ -0,0 +1,41 @@ + + + diff --git a/routes/blog.php b/routes/blog.php index 8307c183..ca391f0c 100644 --- a/routes/blog.php +++ b/routes/blog.php @@ -2,7 +2,7 @@ use Illuminate\Support\Facades\Route; use App\Http\Controllers\Dashboard\ShowHomeController; -use App\Http\Controllers\Dashboard\StoreFileController; + use App\Http\Controllers\Dashboard\Tags\StoreTagController; use App\Http\Controllers\Auth\Profile\EditProfileController; use App\Http\Controllers\Dashboard\Blogs\EditBlogController; @@ -22,7 +22,8 @@ Route::prefix('dashboard')->name('dashboard.')->group(function () { Route::get('/home', ShowHomeController::class)->name('home'); - Route::post('/file/store', StoreFileController::class)->name('file.store'); + Route::get('/file/create', \App\Http\Controllers\Dashboard\Files\CreateFileController::class)->name('files.create'); + Route::post('/file/store', \App\Http\Controllers\Dashboard\Files\StoreFileController::class)->name('files.store'); Route::prefix('blogs')->name('blogs.')->group(function () { Route::get('/', IndexBlogsController::class)->name('index');