Javascript Larvel:尝试访问视图模板中数组内的值

Javascript Larvel:尝试访问视图模板中数组内的值,javascript,php,arrays,laravel,Javascript,Php,Arrays,Laravel,因此,我试图在我创建的数组中访问几对key->value的值,并将其传递给名为config的视图,我希望这样访问它们:{{$config->web_name['value']}或{$config->$web_name['value']},但两者都返回错误 以下是我将数据传递到视图的方式: public function inicio() { $pageInfo = [ 'page_title' => 'Inici

因此,我试图在我创建的数组中访问几对
key->value
的值,并将其传递给名为config的视图,我希望这样访问它们:
{{$config->web_name['value']}
{$config->$web_name['value']}
,但两者都返回错误

以下是我将数据传递到视图的方式:

public function inicio()
    {

        $pageInfo = 
        [
            'page_title'      => 'Inicio',
            'menu_active'     => 'Inicio',
            'submenu_active' => '',
        ];

        $globals = Globals::all();

        $web_name = $globals->where('name', 'Nombre del restaurante')->first();
        $web_description = $globals->where('name', 'Descripcion en google del restaurante')->first();
        $restaurant_bio = $globals->where('name', 'Biografia del restaurante')->first();
        $booking_phone = $globals->where('name', 'Télefono de reserva')->first();
        $client_mail = $globals->where('name', 'Email de contacto')->first();
        $full_address = $globals->where('name', 'Dirección del restaurante')->first();
        $city_zip_address = $globals->where('name', 'Código postal y ciudad')->first();

        $config = compact('web_name', 'web_description');

        $sliders = Slider::all();


        return view('inicio.index', compact('pageInfo', 'config', 'sliders', 'web_name'));
    }

您试图使用像对象一样传递到视图的变量,但是当您使用
compact()
时,您正在使它们成为
array
。因此,要访问您的数据,请执行以下操作:

{{ $config['web_name']['value'] }}

试试下面。此外,还将压缩$web_name两次

{{$web_name['value']}}

粘贴错误详细信息尝试获取非对象(视图:C:\xampp\htdocs\Restaurante1\resources\views\inicio\index.blade.php)的属性“web\u name”)您的$config不是对象。它是数组。读一下错误,解释得很好。