예제 #1
0
파일: Select.php 프로젝트: iyoworks/former
 /**
  * Use the results from a Fluent/Eloquent query as options
  *
  * @param  array  $results  An array of Eloquent models
  * @param  string $value    The attribute to use as text
  * @param  string $key      The attribute to use as value
  */
 public function fromQuery($results, $value = null, $key = null)
 {
     $options = Helpers::queryToArray($results, $value, $key);
     if (isset($options)) {
         $this->options = $options;
     }
 }
예제 #2
0
파일: Input.php 프로젝트: raftalks/former
 /**
  * Adds a datalist to the current field
  *
  * @param  array $datalist An array to use a source
  */
 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;
 }
예제 #3
0
 /**
  * Creates a serie 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++;
     }
 }
예제 #4
0
파일: Select.php 프로젝트: GhDj/erp-fac-fin
 /**
  * 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
  */
 public function fromQuery($results, $text = null, $attributes = null)
 {
     $this->options(Helpers::queryToArray($results, $text, $attributes));
     return $this;
 }
예제 #5
0
 /**
  * Use the results from a Fluent/Eloquent query as options
  *
  * @param  array  $results  An array of Eloquent models
  * @param  string $value    The attribute to use as text
  * @param  string $key      The attribute to use as value
  */
 public function fromQuery($results, $value = null, $key = null)
 {
     $this->options(Helpers::queryToArray($results, $value, $key));
     return $this;
 }