Q:

Format for resources wrapper for dates returned from Settings table

In Laravel 6 app I make resources wrapper for dates returned from Settings table (pairs of name => value), but I got returned data in invalid format, not pairs of name => value.
I have in controller:
$settingsArray= [];
$settingValues= Settings::getSettingsList();
foreach( $settingValues as $nextSettingValue ) {
    $settingsArray[$nextSettingValue->name] = $nextSettingValue->value;
}

\Log::info('$settingsArray ::');
\Log::info(print_r(  $settingsArray, true  ));

return (new SettingsCollection($settingsArray));

Output of logging above is:
[2020-04-21 07:47:07] local.INFO: $settingsArray ::  
[2020-04-21 07:47:07] local.INFO: Array
(
    [site_name] => VTasks
    [copyright_text] => © 2019 - 2020 All rights reserved
    [site_heading] => Task 'em all
    [backend_items_per_page] => 2
    [tasks_per_page] => 4
    [events_per_page] => 5
    [events_demo_month] => 2018-02-01
)

and in app/Http/Controllers/API/Admin/SettingsController.php:
class SettingsCollection extends ResourceCollection
{
    public static $wrap = 'settings';

    public function toArray($request)
    {
        \Log::info('SettingsCollection $request::');
        \Log::info(print_r(  json_encode($request), true  ));
        \Log::info('+++ SettingsCollection $this::');
        \Log::info(print_r(  json_encode($this), true  ));

        return $this->collection->transform(function($settings, $key){
            \Log::info('+++ $settings:');
            \Log::info(print_r(  json_encode($settings), true  ));
            \Log::info('+++ $key:');
            \Log::info(print_r(  json_encode($key), true  ));

            return [
                $key => $settings,
            ];
        });
    }

I see in log output:
[2020-04-21 07:47:07] local.INFO: "tasks_per_page"  
[2020-04-21 07:47:07] local.INFO: +++ $settings:  
[2020-04-21 07:47:07] local.INFO: "5"  
[2020-04-21 07:47:07] local.INFO: +++ $key:  
[2020-04-21 07:47:07] local.INFO: "events_per_page"  
[2020-04-21 07:47:07] local.INFO: +++ $settings:  
[2020-04-21 07:47:07] local.INFO: "2018-02-01"  
[2020-04-21 07:47:07] local.INFO: +++ $key:  
[2020-04-21 07:47:07] local.INFO: "events_demo_month"  
[2020-04-21 07:47:07] local.INFO: {"site_name":{"site_name":"VTasks"},"copyright_text":{"copyright_text":"\u00a9 2019 - 2020 All rights reserved"},"site_heading":{"site_heading":"Task 'em all"},"backend_items_per_page":{"backend_items_per_page":"2"},"tasks_per_page":{"tasks_per_page":"4"},"events_per_page":{"events_per_page":"5"},"events_demo_month":{"events_demo_month":"2018-02-01"}}  

And returned data has wrong structure: https://imgur.com/a/CvIAAQO
Which is the valid way?

A:

I think this is what you're looking for:
class SettingsCollection extends ResourceCollection
{
    public static $wrap = 'settings';

    public function toArray($request)
    {
        return $this->collection->toArray();
    }

