Level 58
You can achieve this using Laravel's pluck method. Here's an example:
$userArray = User::where('id', '>', 10)->pluck('name', 'id')->toArray();
This will give you an array where the keys are the user IDs and the values are the user names. The pluck method selects the name and id columns from the users table and creates an array where the id column is used as the key and the name column is used as the value. The toArray method is used to convert the collection to an array.
1 like