So I'm trying to access the value of a few pair of key->values
inside an array I create and pass to the view called config, I'd like to access to them like this : {{ $config->web_name['value'] }}
or {{ $config->$web_name['value'] }}
but both are returning errors.
This is how I pass the data to my view:
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'));
}
You are trying to use variables passed to your views like objects, but when you do compact()
you are making them arrays
. So to access your data do something like this:
{{ $config['web_name']['value'] }}
Try below. Also, you are compacting $web_name twice.
{{$web_name['value']}}