1

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'));
    }
3
  • Paste the errors detail Commented Jul 11, 2018 at 16:13
  • Trying to get property 'web_name' of non-object (View: C:\xampp\htdocs\Restaurante1\resources\views\inicio\index.blade.php) Commented Jul 11, 2018 at 16:14
  • Your $config isn't object. It's array. Read the error a little bit, it explains it very good. Commented Jul 11, 2018 at 16:17

2 Answers 2

2

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'] }}
Sign up to request clarification or add additional context in comments.

Comments

0

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

{{$web_name['value']}}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.