From 30eac6350000b873cea3c93476707f69871f7878 Mon Sep 17 00:00:00 2001 From: Geni Jaho Date: Mon, 19 Aug 2024 22:38:22 +0200 Subject: [PATCH] Update photo exports (#66) * Update photos export JSON format * Add photos export CSV format * Add headings for CSV export --- app/Actions/Photos/ExportPhotosAction.php | 3 +- app/DTO/PhotoExport.php | 6 +- app/Exports/PhotosCsvExport.php | 42 ++ .../Photos/ExportPhotosController.php | 10 +- app/Models/Tag.php | 3 + composer.json | 1 + composer.lock | 518 +++++++++++++++++- resources/js/Pages/Photos/Index.vue | 41 +- tests/Feature/Photos/ExportPhotosTest.php | 34 ++ tests/Unit/Actions/ExportPhotosActionTest.php | 5 +- 10 files changed, 645 insertions(+), 18 deletions(-) create mode 100644 app/Exports/PhotosCsvExport.php diff --git a/app/Actions/Photos/ExportPhotosAction.php b/app/Actions/Photos/ExportPhotosAction.php index e236c4ed..0521129e 100644 --- a/app/Actions/Photos/ExportPhotosAction.php +++ b/app/Actions/Photos/ExportPhotosAction.php @@ -16,7 +16,8 @@ public function run(User $user): Generator ->filter($user->settings->photo_filters) ->with(['photoItems' => fn (Builder $q) => $q ->with('item:id,name') - ->with('tags:id,name'), + ->with('tags:id,tag_type_id,name') + ->with('tags.type:id,name'), ]) ->lazyById(); diff --git a/app/DTO/PhotoExport.php b/app/DTO/PhotoExport.php index 52c6b312..0f90b42d 100644 --- a/app/DTO/PhotoExport.php +++ b/app/DTO/PhotoExport.php @@ -4,6 +4,7 @@ use App\Models\Photo; use App\Models\PhotoItem; +use App\Models\Tag; use Illuminate\Support\Collection; use Spatie\LaravelData\Data; @@ -39,7 +40,10 @@ public static function fromModel(Photo $photo): static 'recycled' => $photoItem->recycled, 'deposit' => $photoItem->deposit, 'quantity' => $photoItem->quantity, - 'tags' => $photoItem->tags->pluck('name')->toArray(), + 'tags' => $photoItem->tags->map(fn (Tag $tag): array => [ + 'type' => $tag->type->name, + 'name' => $tag->name, + ])->all(), ]), ); } diff --git a/app/Exports/PhotosCsvExport.php b/app/Exports/PhotosCsvExport.php new file mode 100644 index 00000000..a7fa5fea --- /dev/null +++ b/app/Exports/PhotosCsvExport.php @@ -0,0 +1,42 @@ + $photos + */ + public function __construct(private Generator $photos) + { + } + + public function generator(): Generator + { + return $this->photos; + } + + /** + * @return string[] + */ + public function headings(): array + { + return [ + 'ID', + 'Original File Name', + 'Latitude', + 'Longitude', + 'Taken At Local', + 'Created At', + 'Items', + ]; + } +} diff --git a/app/Http/Controllers/Photos/ExportPhotosController.php b/app/Http/Controllers/Photos/ExportPhotosController.php index b2b712d2..cabf3945 100644 --- a/app/Http/Controllers/Photos/ExportPhotosController.php +++ b/app/Http/Controllers/Photos/ExportPhotosController.php @@ -3,19 +3,27 @@ namespace App\Http\Controllers\Photos; use App\Actions\Photos\ExportPhotosAction; +use App\Exports\PhotosCsvExport; use App\Http\Controllers\Controller; use App\Models\User; +use Illuminate\Http\Response; +use Maatwebsite\Excel\Excel; +use Symfony\Component\HttpFoundation\BinaryFileResponse; use Symfony\Component\HttpFoundation\StreamedResponse; class ExportPhotosController extends Controller { - public function __invoke(ExportPhotosAction $action): StreamedResponse + public function __invoke(ExportPhotosAction $action): StreamedResponse|BinaryFileResponse|Response { /** @var User $user */ $user = auth()->user(); $photos = $action->run($user); + if (request()->input('format') === 'csv') { + return (new PhotosCsvExport($photos))->download('photos.csv', Excel::CSV); + } + return response()->streamJson(['photos' => $photos], 200, [ 'Content-Type' => 'application/json', 'Content-Disposition' => 'attachment; filename="photos.json"', diff --git a/app/Models/Tag.php b/app/Models/Tag.php index 3f8ddfb8..658aa2f5 100644 --- a/app/Models/Tag.php +++ b/app/Models/Tag.php @@ -7,6 +7,9 @@ use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\Relations\HasMany; +/** + * @property TagType $type + */ class Tag extends Model { use HasFactory; diff --git a/composer.json b/composer.json index 50f63b51..dfc0045b 100644 --- a/composer.json +++ b/composer.json @@ -21,6 +21,7 @@ "laravel/socialite": "^5.11", "laravel/tinker": "^2.8", "league/flysystem-aws-s3-v3": "^3.0", + "maatwebsite/excel": "^3.1", "spatie/laravel-data": "^4.0", "tightenco/ziggy": "^1.0" }, diff --git a/composer.lock b/composer.lock index 64559ee3..2e33676a 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "a95669b85e2b9b07284fa3a4b78b0158", + "content-hash": "23b90fb701ff7728372bed03cf14e64a", "packages": [ { "name": "amphp/amp", @@ -1413,6 +1413,87 @@ ], "time": "2023-12-11T17:09:12+00:00" }, + { + "name": "composer/semver", + "version": "3.4.2", + "source": { + "type": "git", + "url": "https://github.com/composer/semver.git", + "reference": "c51258e759afdb17f1fd1fe83bc12baaef6309d6" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/composer/semver/zipball/c51258e759afdb17f1fd1fe83bc12baaef6309d6", + "reference": "c51258e759afdb17f1fd1fe83bc12baaef6309d6", + "shasum": "" + }, + "require": { + "php": "^5.3.2 || ^7.0 || ^8.0" + }, + "require-dev": { + "phpstan/phpstan": "^1.4", + "symfony/phpunit-bridge": "^4.2 || ^5" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "3.x-dev" + } + }, + "autoload": { + "psr-4": { + "Composer\\Semver\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nils Adermann", + "email": "naderman@naderman.de", + "homepage": "http://www.naderman.de" + }, + { + "name": "Jordi Boggiano", + "email": "j.boggiano@seld.be", + "homepage": "http://seld.be" + }, + { + "name": "Rob Bast", + "email": "rob.bast@gmail.com", + "homepage": "http://robbast.nl" + } + ], + "description": "Semver library that offers utilities, version constraint parsing and validation.", + "keywords": [ + "semantic", + "semver", + "validation", + "versioning" + ], + "support": { + "irc": "ircs://irc.libera.chat:6697/composer", + "issues": "https://github.com/composer/semver/issues", + "source": "https://github.com/composer/semver/tree/3.4.2" + }, + "funding": [ + { + "url": "https://packagist.com", + "type": "custom" + }, + { + "url": "https://github.com/composer", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/composer/composer", + "type": "tidelift" + } + ], + "time": "2024-07-12T11:35:52+00:00" + }, { "name": "danharrin/date-format-converter", "version": "v0.3.0", @@ -2327,6 +2408,67 @@ ], "time": "2023-10-06T06:47:41+00:00" }, + { + "name": "ezyang/htmlpurifier", + "version": "v4.17.0", + "source": { + "type": "git", + "url": "https://github.com/ezyang/htmlpurifier.git", + "reference": "bbc513d79acf6691fa9cf10f192c90dd2957f18c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/ezyang/htmlpurifier/zipball/bbc513d79acf6691fa9cf10f192c90dd2957f18c", + "reference": "bbc513d79acf6691fa9cf10f192c90dd2957f18c", + "shasum": "" + }, + "require": { + "php": "~5.6.0 || ~7.0.0 || ~7.1.0 || ~7.2.0 || ~7.3.0 || ~7.4.0 || ~8.0.0 || ~8.1.0 || ~8.2.0 || ~8.3.0" + }, + "require-dev": { + "cerdic/css-tidy": "^1.7 || ^2.0", + "simpletest/simpletest": "dev-master" + }, + "suggest": { + "cerdic/css-tidy": "If you want to use the filter 'Filter.ExtractStyleBlocks'.", + "ext-bcmath": "Used for unit conversion and imagecrash protection", + "ext-iconv": "Converts text to and from non-UTF-8 encodings", + "ext-tidy": "Used for pretty-printing HTML" + }, + "type": "library", + "autoload": { + "files": [ + "library/HTMLPurifier.composer.php" + ], + "psr-0": { + "HTMLPurifier": "library/" + }, + "exclude-from-classmap": [ + "/library/HTMLPurifier/Language/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "LGPL-2.1-or-later" + ], + "authors": [ + { + "name": "Edward Z. Yang", + "email": "admin@htmlpurifier.org", + "homepage": "http://ezyang.com" + } + ], + "description": "Standards compliant HTML filter written in PHP", + "homepage": "http://htmlpurifier.org/", + "keywords": [ + "html" + ], + "support": { + "issues": "https://github.com/ezyang/htmlpurifier/issues", + "source": "https://github.com/ezyang/htmlpurifier/tree/v4.17.0" + }, + "time": "2023-11-17T15:01:25+00:00" + }, { "name": "filament/actions", "version": "v3.2.83", @@ -5347,6 +5489,275 @@ ], "time": "2024-05-21T13:39:04+00:00" }, + { + "name": "maatwebsite/excel", + "version": "3.1.55", + "source": { + "type": "git", + "url": "https://github.com/SpartnerNL/Laravel-Excel.git", + "reference": "6d9d791dcdb01a9b6fd6f48d46f0d5fff86e6260" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/SpartnerNL/Laravel-Excel/zipball/6d9d791dcdb01a9b6fd6f48d46f0d5fff86e6260", + "reference": "6d9d791dcdb01a9b6fd6f48d46f0d5fff86e6260", + "shasum": "" + }, + "require": { + "composer/semver": "^3.3", + "ext-json": "*", + "illuminate/support": "5.8.*||^6.0||^7.0||^8.0||^9.0||^10.0||^11.0", + "php": "^7.0||^8.0", + "phpoffice/phpspreadsheet": "^1.18", + "psr/simple-cache": "^1.0||^2.0||^3.0" + }, + "require-dev": { + "laravel/scout": "^7.0||^8.0||^9.0||^10.0", + "orchestra/testbench": "^6.0||^7.0||^8.0||^9.0", + "predis/predis": "^1.1" + }, + "type": "library", + "extra": { + "laravel": { + "providers": [ + "Maatwebsite\\Excel\\ExcelServiceProvider" + ], + "aliases": { + "Excel": "Maatwebsite\\Excel\\Facades\\Excel" + } + } + }, + "autoload": { + "psr-4": { + "Maatwebsite\\Excel\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Patrick Brouwers", + "email": "patrick@spartner.nl" + } + ], + "description": "Supercharged Excel exports and imports in Laravel", + "keywords": [ + "PHPExcel", + "batch", + "csv", + "excel", + "export", + "import", + "laravel", + "php", + "phpspreadsheet" + ], + "support": { + "issues": "https://github.com/SpartnerNL/Laravel-Excel/issues", + "source": "https://github.com/SpartnerNL/Laravel-Excel/tree/3.1.55" + }, + "funding": [ + { + "url": "https://laravel-excel.com/commercial-support", + "type": "custom" + }, + { + "url": "https://github.com/patrickbrouwers", + "type": "github" + } + ], + "time": "2024-02-20T08:27:10+00:00" + }, + { + "name": "maennchen/zipstream-php", + "version": "3.1.0", + "source": { + "type": "git", + "url": "https://github.com/maennchen/ZipStream-PHP.git", + "reference": "b8174494eda667f7d13876b4a7bfef0f62a7c0d1" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/maennchen/ZipStream-PHP/zipball/b8174494eda667f7d13876b4a7bfef0f62a7c0d1", + "reference": "b8174494eda667f7d13876b4a7bfef0f62a7c0d1", + "shasum": "" + }, + "require": { + "ext-mbstring": "*", + "ext-zlib": "*", + "php-64bit": "^8.1" + }, + "require-dev": { + "ext-zip": "*", + "friendsofphp/php-cs-fixer": "^3.16", + "guzzlehttp/guzzle": "^7.5", + "mikey179/vfsstream": "^1.6", + "php-coveralls/php-coveralls": "^2.5", + "phpunit/phpunit": "^10.0", + "vimeo/psalm": "^5.0" + }, + "suggest": { + "guzzlehttp/psr7": "^2.4", + "psr/http-message": "^2.0" + }, + "type": "library", + "autoload": { + "psr-4": { + "ZipStream\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Paul Duncan", + "email": "pabs@pablotron.org" + }, + { + "name": "Jonatan Männchen", + "email": "jonatan@maennchen.ch" + }, + { + "name": "Jesse Donat", + "email": "donatj@gmail.com" + }, + { + "name": "András Kolesár", + "email": "kolesar@kolesar.hu" + } + ], + "description": "ZipStream is a library for dynamically streaming dynamic zip files from PHP without writing to the disk at all on the server.", + "keywords": [ + "stream", + "zip" + ], + "support": { + "issues": "https://github.com/maennchen/ZipStream-PHP/issues", + "source": "https://github.com/maennchen/ZipStream-PHP/tree/3.1.0" + }, + "funding": [ + { + "url": "https://github.com/maennchen", + "type": "github" + }, + { + "url": "https://opencollective.com/zipstream", + "type": "open_collective" + } + ], + "time": "2023-06-21T14:59:35+00:00" + }, + { + "name": "markbaker/complex", + "version": "3.0.2", + "source": { + "type": "git", + "url": "https://github.com/MarkBaker/PHPComplex.git", + "reference": "95c56caa1cf5c766ad6d65b6344b807c1e8405b9" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/MarkBaker/PHPComplex/zipball/95c56caa1cf5c766ad6d65b6344b807c1e8405b9", + "reference": "95c56caa1cf5c766ad6d65b6344b807c1e8405b9", + "shasum": "" + }, + "require": { + "php": "^7.2 || ^8.0" + }, + "require-dev": { + "dealerdirect/phpcodesniffer-composer-installer": "dev-master", + "phpcompatibility/php-compatibility": "^9.3", + "phpunit/phpunit": "^7.0 || ^8.0 || ^9.0", + "squizlabs/php_codesniffer": "^3.7" + }, + "type": "library", + "autoload": { + "psr-4": { + "Complex\\": "classes/src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Mark Baker", + "email": "mark@lange.demon.co.uk" + } + ], + "description": "PHP Class for working with complex numbers", + "homepage": "https://github.com/MarkBaker/PHPComplex", + "keywords": [ + "complex", + "mathematics" + ], + "support": { + "issues": "https://github.com/MarkBaker/PHPComplex/issues", + "source": "https://github.com/MarkBaker/PHPComplex/tree/3.0.2" + }, + "time": "2022-12-06T16:21:08+00:00" + }, + { + "name": "markbaker/matrix", + "version": "3.0.1", + "source": { + "type": "git", + "url": "https://github.com/MarkBaker/PHPMatrix.git", + "reference": "728434227fe21be27ff6d86621a1b13107a2562c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/MarkBaker/PHPMatrix/zipball/728434227fe21be27ff6d86621a1b13107a2562c", + "reference": "728434227fe21be27ff6d86621a1b13107a2562c", + "shasum": "" + }, + "require": { + "php": "^7.1 || ^8.0" + }, + "require-dev": { + "dealerdirect/phpcodesniffer-composer-installer": "dev-master", + "phpcompatibility/php-compatibility": "^9.3", + "phpdocumentor/phpdocumentor": "2.*", + "phploc/phploc": "^4.0", + "phpmd/phpmd": "2.*", + "phpunit/phpunit": "^7.0 || ^8.0 || ^9.0", + "sebastian/phpcpd": "^4.0", + "squizlabs/php_codesniffer": "^3.7" + }, + "type": "library", + "autoload": { + "psr-4": { + "Matrix\\": "classes/src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Mark Baker", + "email": "mark@demon-angel.eu" + } + ], + "description": "PHP Class for working with matrices", + "homepage": "https://github.com/MarkBaker/PHPMatrix", + "keywords": [ + "mathematics", + "matrix", + "vector" + ], + "support": { + "issues": "https://github.com/MarkBaker/PHPMatrix/issues", + "source": "https://github.com/MarkBaker/PHPMatrix/tree/3.0.1" + }, + "time": "2022-12-02T22:17:43+00:00" + }, { "name": "masterminds/html5", "version": "2.9.0", @@ -6366,6 +6777,111 @@ }, "time": "2024-02-23T11:10:43+00:00" }, + { + "name": "phpoffice/phpspreadsheet", + "version": "1.29.0", + "source": { + "type": "git", + "url": "https://github.com/PHPOffice/PhpSpreadsheet.git", + "reference": "fde2ccf55eaef7e86021ff1acce26479160a0fa0" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/PHPOffice/PhpSpreadsheet/zipball/fde2ccf55eaef7e86021ff1acce26479160a0fa0", + "reference": "fde2ccf55eaef7e86021ff1acce26479160a0fa0", + "shasum": "" + }, + "require": { + "ext-ctype": "*", + "ext-dom": "*", + "ext-fileinfo": "*", + "ext-gd": "*", + "ext-iconv": "*", + "ext-libxml": "*", + "ext-mbstring": "*", + "ext-simplexml": "*", + "ext-xml": "*", + "ext-xmlreader": "*", + "ext-xmlwriter": "*", + "ext-zip": "*", + "ext-zlib": "*", + "ezyang/htmlpurifier": "^4.15", + "maennchen/zipstream-php": "^2.1 || ^3.0", + "markbaker/complex": "^3.0", + "markbaker/matrix": "^3.0", + "php": "^7.4 || ^8.0", + "psr/http-client": "^1.0", + "psr/http-factory": "^1.0", + "psr/simple-cache": "^1.0 || ^2.0 || ^3.0" + }, + "require-dev": { + "dealerdirect/phpcodesniffer-composer-installer": "dev-main", + "dompdf/dompdf": "^1.0 || ^2.0", + "friendsofphp/php-cs-fixer": "^3.2", + "mitoteam/jpgraph": "^10.3", + "mpdf/mpdf": "^8.1.1", + "phpcompatibility/php-compatibility": "^9.3", + "phpstan/phpstan": "^1.1", + "phpstan/phpstan-phpunit": "^1.0", + "phpunit/phpunit": "^8.5 || ^9.0 || ^10.0", + "squizlabs/php_codesniffer": "^3.7", + "tecnickcom/tcpdf": "^6.5" + }, + "suggest": { + "dompdf/dompdf": "Option for rendering PDF with PDF Writer", + "ext-intl": "PHP Internationalization Functions", + "mitoteam/jpgraph": "Option for rendering charts, or including charts with PDF or HTML Writers", + "mpdf/mpdf": "Option for rendering PDF with PDF Writer", + "tecnickcom/tcpdf": "Option for rendering PDF with PDF Writer" + }, + "type": "library", + "autoload": { + "psr-4": { + "PhpOffice\\PhpSpreadsheet\\": "src/PhpSpreadsheet" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Maarten Balliauw", + "homepage": "https://blog.maartenballiauw.be" + }, + { + "name": "Mark Baker", + "homepage": "https://markbakeruk.net" + }, + { + "name": "Franck Lefevre", + "homepage": "https://rootslabs.net" + }, + { + "name": "Erik Tilt" + }, + { + "name": "Adrien Crivelli" + } + ], + "description": "PHPSpreadsheet - Read, Create and Write Spreadsheet documents in PHP - Spreadsheet engine", + "homepage": "https://github.com/PHPOffice/PhpSpreadsheet", + "keywords": [ + "OpenXML", + "excel", + "gnumeric", + "ods", + "php", + "spreadsheet", + "xls", + "xlsx" + ], + "support": { + "issues": "https://github.com/PHPOffice/PhpSpreadsheet/issues", + "source": "https://github.com/PHPOffice/PhpSpreadsheet/tree/1.29.0" + }, + "time": "2023-06-14T22:48:31+00:00" + }, { "name": "phpoption/phpoption", "version": "1.9.2", diff --git a/resources/js/Pages/Photos/Index.vue b/resources/js/Pages/Photos/Index.vue index 087ff7bb..f8c65ff7 100644 --- a/resources/js/Pages/Photos/Index.vue +++ b/resources/js/Pages/Photos/Index.vue @@ -14,6 +14,7 @@ import Modal from "@/Components/Modal.vue"; import Dropdown from "@/Components/Dropdown.vue"; import ToggleInput from "@/Components/ToggleInput.vue"; import InputLabel from "@/Components/InputLabel.vue"; +import DropdownLink from "@/Components/DropdownLink.vue"; const props = defineProps({ photos: Object, @@ -157,8 +158,8 @@ const filter = (filters) => { router.get(window.location.pathname, filters); } -const exportData = () => { - window.location.href = route('photos.export'); +const exportData = (format) => { + window.location.href = route('photos.export', {format}); } @@ -224,17 +225,31 @@ const exportData = () => {
- - -
-
- Downloads a JSON file with all the items and - tags of the photos you have filtered -
-
-
- Export Data -
+ + + + + +
diff --git a/tests/Feature/Photos/ExportPhotosTest.php b/tests/Feature/Photos/ExportPhotosTest.php index 55cf4ddf..427e69cd 100644 --- a/tests/Feature/Photos/ExportPhotosTest.php +++ b/tests/Feature/Photos/ExportPhotosTest.php @@ -1,7 +1,13 @@ actingAs($user = User::factory()->create()); @@ -36,3 +42,31 @@ 'photos' => [], ]); }); + +test('the user can download photos in CSV format', function (): void { + Excel::fake(); + $this->actingAs($user = User::factory()->create()); + + $photo = Photo::factory()->for($user)->create(); + + $response = $this->get('/photos/export?format=csv'); + + $response->assertOk(); + + Excel::assertDownloaded('photos.csv', function (PhotosCsvExport $export) use ($photo): bool { + $dto = $export->generator()->current(); + + assertInstanceOf(PhotoExport::class, $dto); + assertSame([ + 'id' => $photo->id, + 'original_file_name' => $photo->original_file_name, + 'latitude' => $photo->latitude, + 'longitude' => $photo->longitude, + 'taken_at_local' => $photo->taken_at_local, + 'created_at' => $photo->created_at->toIso8601String(), + 'items' => [], + ], $dto->toArray()); + + return true; + }); +}); diff --git a/tests/Unit/Actions/ExportPhotosActionTest.php b/tests/Unit/Actions/ExportPhotosActionTest.php index ff2ce93b..a211fc5d 100644 --- a/tests/Unit/Actions/ExportPhotosActionTest.php +++ b/tests/Unit/Actions/ExportPhotosActionTest.php @@ -49,7 +49,10 @@ 'recycled' => $photoItem->recycled, 'deposit' => $photoItem->deposit, 'quantity' => $photoItem->quantity, - 'tags' => [$tag->name], + 'tags' => [[ + 'type' => $tag->type->name, + 'name' => $tag->name, + ]], ]); });