Note that there are some explanatory texts on larger screens.

plurals
  1. POLaravel 3 - How to validate checkbox array, for at least 1 checked?
    primarykey
    data
    text
    <p>I'm starting to learn Laravel and still on the learning curve. Now I'm starting with Laravel 3 but will most probably switch my project into Laravel 4 once I get something working. Now the question being, how to validate an array of checkbox, I want to validate that at least 1 inside the group is enable(checked). I read somewhere on Laravel forum that we just validate them using a required, but when I <code>dd(input::all())</code> I don't see anything else but the inputs field and checkbox are not part of them...</p> <p>Part of my Blade Create code for the checkbox:</p> <pre><code>&lt;label class="checkbox"&gt;{{ Form::checkbox('changeReasons[]', 'ckbCRCertification', Input::had('ckbCRCertification'), array('id' =&gt; 'ckbCRCertification')) }} Certification&lt;/label&gt; &lt;label class="checkbox"&gt;{{ Form::checkbox('changeReasons[]', 'ckbCRDesignCorrection', Input::had('ckbCRDesignCorrection'), array('id' =&gt; 'ckbCRDesignCorrection')) }} Design Correction&lt;/label&gt; </code></pre> <p>My controller (REST) code is:</p> <pre class="lang-php prettyprint-override"><code>public function post_create() { print "Inside the post_create()"; // validate input $rules = array( 'ecoNo' =&gt; 'min:4', 'productAffected' =&gt; 'required', 'changeReasons' =&gt; 'required' ); $validation = Validator::make(Input::all(), $rules); if($validation-&gt;fails()) { return Redirect::back()-&gt;with_input()-&gt;with_errors($validation); } $eco = new Eco; $eco-&gt;ecoNo = Input::get('ecoNo'); $eco-&gt;productAffected = Input::get('productAffected'); $eco-&gt;save(); return Redirect::to('ecos'); } </code></pre> <p>I also want to know the correct code for getting the checkboxes state after a validation fails, I thought I saw the <code>Input::had(checkBoxName)</code> somewhere but that doesn't seem to work, I'm probably not using it correctly and I'm getting a little confuse on that since all example I see are for inputs and nothing else. I assume the validation is roughly the same in L4, would it be?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload