Laravel 5.3 -- Trying to check a checkbox in a dynamic list -


i have collection on user object named prefs contains collection named auctions. when dump user, can confirm such

prefs: {        auctions: {           a320: false,           a330: true,           a340: true,           b737cl: true,           b737ng: true,           b747: true,           b757: true,           b767: true,           b777: true,          regional: true,          expendables: true,          miscellaneous: true     } } 

i trying check checkboxes in list of categories dynamically created (an admin can add more needed) following:

<input type="checkbox" id="{{$cat->cat}}" name="categories[]" value="{{$cat->id}}" {{($user->prefs->auctions->$cat->cat ? 'checked' : '')}}> 

i getting

errorexception in 17b600b2cf36de6dc2af6eb299cce5a13d6e20e0.php line 33: undefined property: illuminate\support\collection::$auctions (view: /users/jgravois/documents/code/_work/uaminc.com/resources/views/members/auction/index.blade.php) 

i think you're wrong in:

$user->prefs->auctions->$cat->cat 

are sure not want do:

$user->prefs->auctions->{$cat->cat} 

in last code $cat->cat calculated first, else ->cat come @ end.

warning: json dump don't tell object or array. know that, need php dump such ones returned var_dump.

if prefs array, have do:

$user->prefs['auctions'][$cat->cat] 

Comments

Popular posts from this blog

java - SSE Emitter : Manage timeouts and complete() -

jquery - uncaught exception: DataTables Editor - remote hosting of code not allowed -

java - How to resolve error - package com.squareup.okhttp3 doesn't exist? -