Pluck

0
Демонстрация метода pluck в коллекциях
app/Http/Controllers/ExampleController.php
                            
<?php
 
namespace App\Http\Controllers;
 
use App\Models\Example;
 
class ExampleController extends Controller
{
public function show($id)
{
$item = Example::findOrFail($id);
 
$selectOptions = $item->categories->pluck('name', 'id')->unique()->all();
 
return view("example.show", ["item" => $item, "selectOptions" => $selectOptions]);
}
}