I pass my view a Campaign Collection. If I do
{{ dd($campaign->campaignCreatives->campaignCreativesData) }}
I get something like
Collection {#348 ▼
#items: array:2 [▼
0 => CampaignCreativesData {#349 ▼
#attributes: array:7 [▼
"id" => "5"
"name" => "creativeOption"
"label" => "Other"
"value" => "sdfsdfsdfsdfsdf"
"campaignCreativesId" => "5"
"created_at" => "2016-03-01 10:24:38"
"updated_at" => "2016-03-01 10:24:38"
]
}
1 => CampaignCreativesData {#350 ▼
#attributes: array:7 [▼
"id" => "4"
"name" => "creativeOption"
"label" => "checkboxSelection"
"value" => "Animated GIF"
"campaignCreativesId" => "5"
"created_at" => "2016-03-01 10:24:38"
"updated_at" => "2016-03-01 10:24:38"
]
}
]
}
If I cast it to an array
{{ dd($campaign->campaignCreatives->campaignCreativesData->toArray()) }}
I get something like
array:2 [▼
0 => array:7 [▼
"id" => "5"
"name" => "creativeOption"
"label" => "Other"
"value" => "sdfsdfsdfsdfsdf"
"campaignCreativesId" => "5"
"created_at" => "2016-03-01 10:24:38"
"updated_at" => "2016-03-01 10:24:38"
]
1 => array:7 [▼
"id" => "4"
"name" => "creativeOption"
"label" => "checkboxSelection"
"value" => "Animated GIF"
"campaignCreativesId" => "5"
"created_at" => "2016-03-01 10:24:38"
"updated_at" => "2016-03-01 10:24:38"
]
]
Now I have several checkboxes, and if the value is in the array, I need to check the checkbox. At the moment I have something like this
{!! Form::checkbox('creativeOptions[]', 'Animated GIF', in_array('Animated GIF', $campaign->campaignCreatives->campaignCreativesData->toArray()), ['class' => 'styled', 'id' => 'checkbox1']) !!}
As you can see, Animated GIF is in the array, but the checkbox is not checked.
How can I get the checkbox checked based on what is in the array?
Thanks
from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/24yuIBH
via IFTTT
Aucun commentaire:
Enregistrer un commentaire