Laravel: Trying to access value inside array in view template

8
July 12, 2018, at 01:40 AM

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'));
    }
Answer 1

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'] }}
Answer 2

Try below. Also, you are compacting $web_name twice.

{{$web_name['value']}}
READ ALSO
Error on sending e-mail via SMTP

Error on sending e-mail via SMTP

This is my code for sending emailBut i am getting error and page keeps loading for long time

49
Use Xdebug with PhpStorm and WSL

Use Xdebug with PhpStorm and WSL

I use WSL (Ubuntu 1614) from Windows 10 as a web server with PHP 7

16
I have a table images and album_images. Is the album_images table unnecessary?

I have a table images and album_images. Is the album_images table unnecessary?

I've created a website where a user can upload a single image or a whole album of images and 3 views - one for displaying all single images, one for displaying all albums (just the title image of each album) and one for displaying all album_images that have album_id...

22
Can you get images from a PHP upload?

Can you get images from a PHP upload?

So I have a page containing PHP that will take multiple images, then save and display them

27