Map
0
Демонстрация метода map в коллекциях
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); $files = $item->files->map(function ($file) { $file["slug"] = Str::slug($file["name"]); return $file; }); return view("example.show", ["item" => $item, "files" => $files]); }}