本文整理汇总了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];
}
示例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;
}
}
示例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();
}
示例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;
}
}
示例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());
}
示例6: toArray
public function toArray()
{
$value = parent::toArray();
$metadata = $this->metadata;
unset($metadata['conditions']);
return ['metadata' => $metadata, 'items' => $value];
}
示例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;
}
示例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'];
}
示例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());
}
示例10: __construct
public function __construct($presenter, Collection $collection)
{
foreach ($collection as $key => $resource) {
$collection->put($key, new $presenter($resource));
}
$this->items = $collection->toArray();
}
示例11: transform
/**
* @param Film|Collection $item
* @return array
*/
public function transform($item)
{
if ($item instanceof Film) {
return $item->toArray();
}
return parent::transform($item);
}
示例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;
}
示例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;
}
示例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);
}
示例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;
}