当前位置: 首页>>代码示例>>PHP>>正文


PHP Collection::toArray方法代码示例

本文整理汇总了PHP中Illuminate\Support\Collection::toArray方法的典型用法代码示例。如果您正苦于以下问题:PHP Collection::toArray方法的具体用法?PHP Collection::toArray怎么用?PHP Collection::toArray使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Illuminate\Support\Collection的用法示例。


在下文中一共展示了Collection::toArray方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: send

 public function send(Collection $data)
 {
     $validator = $this->validator($data->toArray(), $this->type);
     if (!$validator->fails()) {
         Mailer::send("emails.{$this->type}", $data->toArray(), function ($message) use($data) {
             $fromAddress = $data->get('from_address');
             $fromName = $data->get('from_name');
             $toAddress = $data->get('to_address');
             $toName = $data->get('to_name');
             $cc = $data->get('cc[]', []);
             $bcc = $data->get('bcc[]', []);
             // Send the message
             $message->from($fromAddress, $fromName);
             $message->to($toAddress, $toName)->subject($data->get('subject'));
             foreach ($cc as $address) {
                 $message->cc($address, null);
             }
             foreach ($bcc as $address) {
                 $message->bcc($address, null);
             }
         });
     } else {
         // Validation failed
         return ['success' => 0, 'status' => "Failed to validate message", 'messages' => $validator->getMessageBag()->all(), 'data' => $data, 'type' => $this->type];
     }
     if (!count(Mailer::failures())) {
         $this->sent_at = Carbon::now();
         Log::info("Sent {$this->type} email");
         return ['success' => 1, 'status' => "successfully sent message", 'data' => $data, 'type' => $this->type];
     }
     Log::info("Failed to send {$this->type} email");
     return ['success' => 0, 'status' => "failed to send message", 'messages' => "failed to send message", 'data' => $data, 'type' => $this->type];
 }
开发者ID:wdmtech,项目名称:laravel-mail,代码行数:33,代码来源:Mail.php

示例2: can

 /**
  * Return true if user has all permissions
  *
  * @param string|array $permission
  * @param bool $any
  * @return bool
  */
 public function can($permission, $any = false, $prefix = false)
 {
     $this->loadPermissions();
     if ($permission instanceof Model) {
         $permission = $permission->slug;
     }
     if ($prefix) {
         $allSlug = $this->slugPermissions->toArray();
     }
     if (is_array($permission)) {
         if ($prefix) {
             foreach ($permission as $item) {
                 if ($this->checkCanWithPrefix($allSlug, $item) === true) {
                     return true;
                 }
             }
             return false;
         } else {
             foreach ($permission as $item) {
                 if ($this->slugPermissions->search($item) === false) {
                     return false;
                 } elseif ($any === true) {
                     return true;
                 }
             }
             return true;
         }
     }
     if ($prefix) {
         return $this->checkCanWithPrefix($allSlug, $permission) !== false;
     } else {
         return $this->slugPermissions->search($permission) !== false;
     }
 }
开发者ID:thinhbuzz,项目名称:laravel-advanced-authorization,代码行数:41,代码来源:UserAuthorizationTrait.php

示例3: get

 /**
  * @param $path
  *
  * @return array
  *
  * @throws FileManagerException
  */
 public function get()
 {
     $this->sys_path = $this->getPath()->path();
     if (!FileSystem::exists($this->sys_path)) {
         throw new FileManagerException($this, 'err_folder_not_found');
     }
     $this->readDir()->map(function ($item_name) {
         $this->content->push($this->readItem($item_name));
     });
     return $this->content->toArray();
 }
开发者ID:crip-laravel,项目名称:filemanager,代码行数:18,代码来源:FolderContent.php

示例4: getData

 /**
  * @param string $key
  * @return static
  */
 public function getData($key = '')
 {
     $data = $this->meta->getData();
     foreach ($data as $k => $v) {
         $data->put($k, strip_tags(trim(strtr($v, $this->code->toArray()), '-_ ')));
     }
     if ($key) {
         return $data->get($key);
     } else {
         return $data;
     }
 }
开发者ID:darrengopower,项目名称:framework,代码行数:16,代码来源:Optimization.php

示例5: testItFiltersToASingleAuthor

 /**
  * Test that our results can be filtered down to a single author.
  */
 public function testItFiltersToASingleAuthor()
 {
     $authorResults = new Collection(['Steven King' => new Collection(), 'Stephen King' => new Collection()]);
     $actual = $this->resultCleaner->clean('Steven King', $authorResults, true);
     $expected = new Collection(['Steven King' => new Collection()]);
     $this->assertEquals($expected->toArray(), $actual->toArray());
 }
开发者ID:ScottBurfieldMills,项目名称:BookFeed,代码行数:10,代码来源:ResultsCleanerTest.php

示例6: toArray

 public function toArray()
 {
     $value = parent::toArray();
     $metadata = $this->metadata;
     unset($metadata['conditions']);
     return ['metadata' => $metadata, 'items' => $value];
 }
开发者ID:minutephp,项目名称:framework,代码行数:7,代码来源:CollectionEx.php

示例7: getFilters

 /**
  * Get all filters
  *
  * @param bool $to_array If true will return filters as array. Default set to false.
  *
  * @return array|Collection
  */
 public function getFilters($to_array = true)
 {
     if ($to_array === true) {
         return $this->filters->toArray();
     }
     return $this->filters;
 }
开发者ID:dyankov91,项目名称:datagrid,代码行数:14,代码来源:Datagrid.php

示例8: findDependenciesForKey

 /**
  * Find in which collection the given dependency exists
  * @param string $dependency
  * @return array
  */
 private function findDependenciesForKey($dependency)
 {
     if ($this->css->get($dependency)) {
         return [$this->css->toArray(), 'css'];
     }
     return [$this->js->toArray(), 'js'];
 }
开发者ID:ruscon,项目名称:Core,代码行数:12,代码来源:AsgardAssetPipeline.php

示例9: getTest

 public function getTest()
 {
     $numberInitial = 200;
     $numberMarried = floor($numberInitial * 10 / 100);
     $genders = [Personnage::GENDER_FEMALE, Personnage::GENDER_MALE];
     $chars = new Collection();
     for ($i = 0; $i < $numberInitial; $i++) {
         $char = new Personnage();
         $chars->push($char);
         $char->setGender($genders[array_rand($genders)]);
         $char->setAge(random_int(1, 60));
         $char->setName($i);
     }
     //Create some marriages
     foreach ($chars as $char) {
         if ($char->age > 15) {
             $numberMarried--;
             $spouse = new Personnage();
             $spouse->setAge(max(15, random_int($char->age - 5, $char->age + 5)));
             $spouse->setGender($char->gender == Personnage::GENDER_MALE ? Personnage::GENDER_FEMALE : Personnage::GENDER_MALE);
             $spouse->setName("Spouse {$numberMarried}");
             $relation = new MarriedTo($spouse, $char);
             $spouse->addRelation($relation);
             $chars->push($spouse);
             //Get them some babies!
             $totalBabies = random_int(0, min(abs($char->age - $spouse->age), 5));
             $siblings = [];
             for ($i = 0; $i < $totalBabies; $i++) {
                 $child = new Personnage();
                 $child->setGender($genders[array_rand($genders)]);
                 $child->setName("Child {$numberMarried}.{$i}");
                 $relation1 = new ParentOf($char, $child);
                 $relation2 = new ParentOf($spouse, $child);
                 $char->addRelation($relation1);
                 $spouse->addRelation($relation2);
                 $chars->push($child);
                 foreach ($siblings as $sibling) {
                     $relation = new SiblingOf($sibling, $child);
                     $sibling->addRelation($relation);
                 }
                 $siblings[] = $child;
             }
         }
         if ($numberMarried <= 0) {
             break;
         }
     }
     /*$man1 = new Personnage();
             $woman1 = new Personnage();
     
             $man1->setName('man1');
             $woman1->setName('woman1');
     
             $man1->setAge(random_int(20, 50));
             $woman1->setAge(max(15,random_int($man1->age - 5, $man1->age + 5)));
     
             $married = new MarriedTo($man1, $woman1);
             $man1->addRelation($married);*/
     echo implode('<br/>', $chars->toArray());
 }
开发者ID:Cadrach,项目名称:dimensions,代码行数:60,代码来源:PlotterController.php

示例10: __construct

 public function __construct($presenter, Collection $collection)
 {
     foreach ($collection as $key => $resource) {
         $collection->put($key, new $presenter($resource));
     }
     $this->items = $collection->toArray();
 }
开发者ID:palmabit,项目名称:library,代码行数:7,代码来源:PresenterCollection.php

示例11: transform

 /**
  * @param Film|Collection $item
  * @return array
  */
 public function transform($item)
 {
     if ($item instanceof Film) {
         return $item->toArray();
     }
     return parent::transform($item);
 }
开发者ID:filmoteca,项目名称:filmoteca,代码行数:11,代码来源:FilmTransformer.php

示例12: run

 /**
  * @param \Illuminate\Support\Collection $rules
  * @param \Illuminate\Database\Eloquent\Model|\Illuminate\Database\Eloquent\Relations\Relation|\Illuminate\Database\Query\Builder $query
  * @return \Illuminate\Database\Eloquent\Model|\Illuminate\Database\Eloquent\Relations\Relation|\Illuminate\Database\Query\Builder
  */
 protected function run($rules, $query)
 {
     $query = $query->where(function ($q) use($rules) {
         $this->rules($q, $rules->toArray());
     });
     //echo $query->toSql(); exit;
     return $query;
 }
开发者ID:alex-oliveira,项目名称:ao-scrud,代码行数:13,代码来源:RulesCriteria.php

示例13: compileTableFooter

 /**
  * Compile table footer contents.
  *
  * @return array
  */
 private function compileTableFooter()
 {
     $footer = [];
     foreach ($this->collection->toArray() as $row) {
         $footer[] = '<th>' . $row['footer'] . '</th>';
     }
     return $footer;
 }
开发者ID:rikardote,项目名称:agenda,代码行数:13,代码来源:Builder.php

示例14: convert

 /**
  * Convert a value to XML.
  *
  * @param Collection $value
  * @param SimpleXMLElement $element
  * @return SimpleXMLElement
  * @throws CantConvertValueException
  */
 public function convert($value, SimpleXMLElement $element) : SimpleXMLElement
 {
     if (!$value instanceof Collection) {
         throw new CantConvertValueException("Value is not a collection.");
     }
     // Hand off an array form of the collection to another converter.
     return Xml::convert($value->toArray(), $element);
 }
开发者ID:fetchleo,项目名称:laravel-xml,代码行数:16,代码来源:CollectionConverter.php

示例15: validate

 public function validate(Collection $attrs)
 {
     $check = $this->validator->make($attrs->toArray(), $this->policy->createRules());
     if ($check->fails()) {
         $this->log->debug('Action create by email failed validation.', $check->errors()->all());
         return false;
     }
     return true;
 }
开发者ID:hughfletcher,项目名称:nuticket,代码行数:9,代码来源:ActionPipe.php


注:本文中的Illuminate\Support\Collection::toArray方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。