コード例 #1
0
ファイル: Input.php プロジェクト: laralite/form
 /**
  * Adds a datalist to the current field
  *
  * @param  array  $datalist An array to use a source
  * @param  string $value    The field to use as value
  * @param  string $key      The field to use as key
  */
 public function useDatalist($datalist, $value = null, $key = null)
 {
     $datalist = Helpers::queryToArray($datalist, $value, $key);
     $list = $this->list ?: 'datalist_' . $this->name;
     // Create the link to the datalist
     $this->list = $list;
     $this->datalist = $datalist;
     return $this;
 }
コード例 #2
0
ファイル: Select.php プロジェクト: laralite/form
 /**
  * Use the results from a Fluent/Eloquent query as options
  *
  * @param  array           $results    An array of Eloquent models
  * @param  string|function $text       The value to use as text
  * @param  string|array    $attributes The data to use as attributes
  * @param  string	   $selected   The default selected item
  */
 public function fromQuery($results, $text = null, $attributes = null, $selected = null)
 {
     $this->options(Helpers::queryToArray($results, $text, $attributes), $selected);
     return $this;
 }
コード例 #3
0
ファイル: Checkable.php プロジェクト: laralite/form
 /**
  * Creates a series of checkable items
  *
  * @param array $_items Items to create
  */
 protected function items($_items)
 {
     // If passing an array
     if (sizeof($_items) == 1 and isset($_items[0]) and is_array($_items[0])) {
         $_items = $_items[0];
     }
     // Fetch models if that's what we were passed
     if (isset($_items[0]) and is_object($_items[0])) {
         $_items = Helpers::queryToArray($_items);
         $_items = array_flip($_items);
     }
     // Iterate through items, assign a name and a label to each
     $count = 0;
     foreach ($_items as $label => $name) {
         // Define a fallback name in case none is found
         $fallback = $this->isCheckbox() ? $this->name . '_' . $count : $this->name;
         // Grouped fields
         if ($this->isGrouped()) {
             $attributes['id'] = str_replace('[]', null, $fallback);
             $fallback = str_replace('[]', null, $this->name) . '[]';
         }
         // If we haven't any name defined for the checkable, try to compute some
         if (!is_string($label) and !is_array($name)) {
             $label = $name;
             $name = $fallback;
         }
         // If we gave custom information on the item, add them
         if (is_array($name)) {
             $attributes = $name;
             $name = array_get($attributes, 'name', $fallback);
             unset($attributes['name']);
         }
         // Store all informations we have in an array
         $item = array('name' => $name, 'label' => Helpers::translate($label), 'count' => $count);
         if (isset($attributes)) {
             $item['attributes'] = $attributes;
         }
         $this->items[] = $item;
         $count++;
     }
 }