MapWithKeys
0
Демонстрация метода mapWithKeys в коллекциях
app/Http/Controllers/ExampleController.php
<?php namespace App\Http\Controllers; use App\Models\Example;use Illuminate\Support\Str; class ExampleController extends Controller{ public function show($id) { $item = Example::findOrFail($id); $images = $item->images->mapWithKeys(function ($image) { return [$image->getExtension() => $image->getSize()]; }); return view("example.show", ["item" => $item, "images" => $images]); }}