Other Laravel 4.2 to Laravel 5.0

Published 8 months ago by javineo

My problems continue making Laravel 4.2 become Laravel 5.0.

This is a error:

Undefined property: Illuminate\Database\Eloquent\Collection::$socios (View: C:\NeoWebServer\www\homebanking5\resources\views\submenus\operaciones.blade.php) 

line of code that gives the eror in the view

@if(Session::has('es_socio') && Session::get('es_socio') == '1' && $modulo->socios && $modulo->getItemsEnabled('escritorio') > 0)

$ module comes from model Model.php

    public function getItemsEnabled($menu = 'escritorio'){
        $count = 0;
        
        foreach($this->items as $i){
            if($i->$menu){
                $count++;
            }
            Log::info($count);
        }

        return $count;

What is my mistake? I can not understand what happens, I appreciate if someone can help me with this new error.

Best Answer (As Selected By javineo)
bobbybouwmann

You can call $modulo->socios since $modulo is a collection of items. You either need to loop over it or use one of the collection methods.

What exactly are you trying to achieve?

bobbybouwmann

You can't call socios on $modulo. What kind of object is $modulo?

You can see the available properties by adding this to your code

dd($modulo); 
javineo

This is the result of dd ($ module);

Collection {#335 ▼
  #items: array:3 [▼
    0 => Modulo {#336 ▼
      #sluggable: array:2 [▼
        "build_from" => "modulo"
        "save_to" => "slug"
      ]
      #table: "modules"
      +timestamps: false
      #connection: null
      #primaryKey: "id"
      #perPage: 15
      +incrementing: true
      #attributes: array:7 [▼
        "id" => 1
        "modulo" => "Consultas"
        "socios" => 1
        "comercios" => 1
        "socios_redireccion" => ""
        "comercios_redireccion" => ""
        "slug" => "consultas"
      ]
      #original: array:7 [▼
        "id" => 1
        "modulo" => "Consultas"
        "socios" => 1
        "comercios" => 1
        "socios_redireccion" => ""
        "comercios_redireccion" => ""
        "slug" => "consultas"
      ]
      #relations: []
      #hidden: []
      #visible: []
      #appends: []
      #fillable: []
      #guarded: array:1 [▼
        0 => "*"
      ]
      #dates: []
      #casts: []
      #touches: []
      #observables: []
      #with: []
      #morphClass: null
      +exists: true
    }
    1 => Modulo {#337 ▼
      #sluggable: array:2 [▼
        "build_from" => "modulo"
        "save_to" => "slug"
      ]
      #table: "modules"
      +timestamps: false
      #connection: null
      #primaryKey: "id"
      #perPage: 15
      +incrementing: true
      #attributes: array:7 [▼
        "id" => 2
        "modulo" => "Operaciones"
        "socios" => 1
        "comercios" => 1
        "socios_redireccion" => ""
        "comercios_redireccion" => ""
        "slug" => "operaciones"
      ]
      #original: array:7 [▼
        "id" => 2
        "modulo" => "Operaciones"
        "socios" => 1
        "comercios" => 1
        "socios_redireccion" => ""
        "comercios_redireccion" => ""
        "slug" => "operaciones"
      ]
      #relations: []
      #hidden: []
      #visible: []
      #appends: []
      #fillable: []
      #guarded: array:1 [▼
        0 => "*"
      ]
      #dates: []
      #casts: []
      #touches: []
      #observables: []
      #with: []
      #morphClass: null
      +exists: true
    }
    2 => Modulo {#338 ▼
      #sluggable: array:2 [▼
        "build_from" => "modulo"
        "save_to" => "slug"
      ]
      #table: "modules"
      +timestamps: false
      #connection: null
      #primaryKey: "id"
      #perPage: 15
      +incrementing: true
      #attributes: array:7 [▼
        "id" => 3
        "modulo" => "Servicios Moviles"
        "socios" => 0
        "comercios" => 0
        "socios_redireccion" => ""
        "comercios_redireccion" => ""
        "slug" => "servicios-moviles"
      ]
      #original: array:7 [▼
        "id" => 3
        "modulo" => "Servicios Moviles"
        "socios" => 0
        "comercios" => 0
        "socios_redireccion" => ""
        "comercios_redireccion" => ""
        "slug" => "servicios-moviles"
      ]
      #relations: []
      #hidden: []
      #visible: []
      #appends: []
      #fillable: []
      #guarded: array:1 [▼
        0 => "*"
      ]
      #dates: []
      #casts: []
      #touches: []
      #observables: []
      #with: []
      #morphClass: null
      +exists: true
    }
  ]
}

bobbybouwmann

You can call $modulo->socios since $modulo is a collection of items. You either need to loop over it or use one of the collection methods.

What exactly are you trying to achieve?

javineo

I reviewed the explained and I managed to adapt the code to my needs. They are only 3 sections so what solutions do the following:

@if(Session::has('es_socio') && Session::get('es_socio') == '1' && $modulo[0]->socios && $modulo[0]->getItemsEnabled('escritorio') > 0)

and for the other section the corresponding:

@if(Session::has('es_socio') && Session::get('es_socio') == '1' && $modulo[1]->socios && $modulo[1]->getItemsEnabled('escritorio') > 0)

and the third and last section not yet the development.

Thanks for your help Dutch Wandering

Please sign in or create an account to participate in this conversation.