teleren/devto huggingface dataset:
Laravel Internals: Complex Array building
Tags: laravel, php
Published: 2021-07-22 17:58:48

---
title: Laravel Internals: Complex Array building
published: true
date: 2021-07-06 10:03:56 UTC
tags: laravel,php
canonical_url: 
---

![](https://cdn-images-1.medium.com/max/1024/0*-AL8ySmJ-31hpa_t)<figcaption>Photo by <a href="https://unsplash.com/@ballonandon?utm_source=medium&amp;utm_medium=referral">Ben Allan</a> on <a href="https://unsplash.com?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption>

One of the most common issues you can have in PHP is merging arrays and the complications of having to selectively include or exclude particular keys when needed. Laravel actually has a built in trait for this that’s great to use for these situations.

If you use [Laravel’s HTTP resources](https://laravel.com/docs/8.x/eloquent-resources) you’ll be familiar with this developer experience. Under the hood resources in Laravel rely on the _ConditionallyLoadAttributes_ trait.

To keep things clear in the example I’ve created two models, _Person_ and _Address_, with Address being a _hasOne_ relation for the Person. The example class is simply called _TransformObjectToArray_ which has a method called _transform_ which accepts a Person and an additional array of attributes.

{% gist https://gist.github.com/peterfox/c0270f63affd6797da4f2c34cc7b84f7 %}

This is workable but it often becomes complicated and harder to read.

And here’s how we could do this if we used the _ConditionallyLoadAttributes_ trait instead.

{% gist https://gist.github.com/peterfox/434e2295d6fb8667f681785e3998a0c1 %}

As you can see in the example we have everything neatly occuring in a return statement that shows us what the structure of the array will look like somewhat.

If you’re struggling to understand the functionality of the _when_ and _merge_ methods used in the example you can read about them in the Laravel docs as part of the [resources documentation](https://laravel.com/docs/8.x/eloquent-resources#conditional-attributes). The filter method is purely there to perform the action of handling the operations to remove keys or merge arrays. All of these methods are provided via the trait.

The _ConditionallyLoadAttributes_ trait is something truly worth using in your own classes when developing with Laravel when working with building complex arrays outside of the typical API Responses.

I’m Peter Fox, a software developer in the UK who works with Laravel among other things. Thank you for reading my article, I’ve got several more on both medium and dev.to. If you want to know more about me, head over to [https://www.peterfox.me](https://www.peterfox.me/). Also feel free to follow me @[SlyFireFox](https://twitter.com/SlyFireFox) on twitter for more Laravel tips and tutorials in the future.
June 2021 update - HashiCorp partnership, Env0 and Spacelift!
Tags: terraform, devops, azure, aws
Published: 2021-07-06 10:00:28


In June we focused on integrations and adding more resource coverage. You can [upgrade](https://www.infracost.io/docs/#1-install-infracost) to the latest version (v0.9.2) to pickup the new features. If you are using v0.8 please follow the [v0.9 migration guide](https://www.infracost.io/docs/guides/v0.9_migration).

### ⚙️ Integrations

Infracost already has [CI/CD integrations](https://www.infracost.io/docs/integrations/cicd/) with GitHub Actions, GitLab CI, Atlantis, Azure DevOps, CircleCI, Bitbucket Pipelines and Jenkins. This list keeps growing, so please let us know what you'd like to see added next. Infracost can now be used with the following infra-as-code management platforms too:

- **Terraform Cloud**: we have partnered with HashiCorp to bring cloud cost estimates into Terraform Cloud's new RunChecks (currently in beta). Armon Dadgar, co-founder and CTO of HashiCorp, announced the partnership during HashiConf EU; screenshot below! If your company uses Terraform Cloud and would like to work with us and HashiCorp together on this integration, please reply to this email.

- **Env0**: cloud cost estimates can easily be [enabled in Env0](https://docs.env0.com/docs/cost-estimation). Our CEO Hassan, Env0's CEO Ohad Maislish, and Tim Davis are doing a webinar about cloud costs shifting left on 14th July. [Signup to listen in](https://www.brighttalk.com/webcast/18739/496711/shifting-left-cloud-cost-with-infrastructure-as-code).

- **Spacelift**: cloud cost estimates can also be [enabled in Spacelift](https://docs.spacelift.io/vendors/terraform/infracost).

### ⛅ New cloud resources

Infracost now supports over 200 Terraform resources across AWS, Azure and Google. Over 500 free resources have also been identified; these are not shown in the CLI output since they are free.

We added support for the following cloud resources:
- **AWS**: Backup, EFS One Zone, Kinesis Firehose & Data Analytics, Neptune.
- **Google**: BigQuery, Load Balancer, VPN tunnel.
- **Azure**: Application Gateway, Application Insights, Automation, Cognitive Search, Event Hubs, Kubernetes Load Balancer & HTTP Application Routing, Load Balancer, Redis Cache.

### ⌨️ Shell completion

Run `infracost completion --help` to see how you can generate shell completion scripts for Bash, Zsh, fish and PowerShell. Once enabled, you can use the usual double tab to see autocomplete and help text for commands and flags.

Thanks for being part of the community! We look forward to hearing your feedback via [GitHub issues](https://github.com/infracost/infracost/issues/) or our [community Slack chat](https://www.infracost.io/community-chat).
Spark : Replace collect()[][]
Tags: spark
Published: 2021-07-06 09:40:41

I am having code as:
```
new_df=spark.sql("Select col1,col2 from table1 where id=2").collect()[0][0]
```
I have tried toLocalIterator() but getting message that is not subscriptable.
Please suggest a better way to replace collect()[0][0].
How to Tackle the Hurdles While Searching for Your First Job on Upwork?
Published: 2021-07-06 09:35:07

Upwork is one of the great freelancing marketplaces. For new freelancers, getting their first <a href="https://www.geeksread.com/how-to-tackle-the-hurdles-while-searching-for-your-first-job-on-upwork/">Job on Upwork</a> can be a great start to their freelancing career. While bidding, new freelancers are very excited, they assume to be hired immediately. It’s true in a few cases but not in all. Getting the first job on Upwork can be very exhausting for fresh freelancers, as many experienced freelancers also bid on the job on Upwork. If he knows how to stand out differently from the crowd, he can be the one who gets the job. So, getting the first job on Upwork is the toughest target. Once you surmount that barrier and get positive feedback, it will open the door of opportunities for you. Of course, there are reasons for the obstacles in getting job opportunities. In this article, we will discuss those hurdles and the way to overcome them.
Evrone at Highload++ 2021: stands, games, magic
Tags: ruby, python, eventdriven, eventsinyourcity
Published: 2021-07-06 09:09:53

Highload is the largest professional IT conference for developers of high-load systems. It has been held since 2007, and during this time more than 22,000 people have taken part in it.

In 2021, Highload++ Spring was held on May 17–18 in Moscow, with a limited number of participants. Due to coronavirus restrictions, 9000 sq. meters could only accommodate 1600 people. But the exhibition turned out to be the largest in history. [It had 30 company stands, and one of them was from Evrone.](https://evrone.com/highloadconf)

We’ve been presenting at and attending conferences for years, and we became Highload partners back in 2020. However, due to the pandemic, some of the events that year were canceled, and some were moved online. But in 2021, we participated in full. We showed films about ourselves at the stand and gave a presentation in the main hall.
Types of Data Binding in Angular
Tags: angular, javascript, webdev, typescript
Published: 2021-07-06 09:06:11



Data binding is the automatic synchronization of data between model and view. In Angular, we have 3 fundamental ways to make to-and-fro binding between view and source.


1. Source to View (one-way)
2. View to Source (one-way)
3. View to Source to View (two-way)


## Source to View (one-way)
This refers to as *Property binding* method, it includes all following patterns to share data from source to view.

### Interpolation
Interpolation refers to embedding expressions into markup text. By default Angular interpolation uses `{{` and `}}` to encapsulates the expression. 

```
<p>{{title}}</p>
<div><img src="{{itemImageUrl}}"></div>
```


### Property Binding
The `[]` brackets cause Angular to consider right-hand side value as dynamic, without brackets Angular evaluates the right-hand value as static string.

```
<img [src]="itemImageUrl">
<app-item-detail childItem="parentItem"></app-item-detail> 

```

### Attribute, Style and class binding

#### Attribute bindings
Apart from element properties, we have element attributes [ARIA](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA) and [SVG](https://developer.mozilla.org/en-US/docs/Web/SVG) for which we can use attribute bindings:
```
<button [attr.aria-label]="actionName">{{actionName}} with Aria</button>
```  


#### Class binding
Single class binding
```
[class.sale]="onSale"
```

Multiple Class bindings
```
[class]="'my-class-1 my-class-2 my-class-3'"
```

#### Styles binding
Single style binding
```
<nav [style.background-color]="expression"></nav>
```

Multiple styles binding
```
<nav [style]="stylesExpression"></nav>
```

---

## View to Source (one-way)
More specifically, we call this *Custom Event binding*, utilizing Angular [Event Emitter](https://angular.io/api/core/EventEmitter). 

Consider the following code showing button which alerts on click. The alert content is passed through `<app-button>` component template using custom event `showMessage()`:

{% codesandbox sparkling-sea-quywp %}

## 3. View to Source to View (two-way)
Angular two-way data binding is the combination of square brackets `[]` and parentheses `()`. `[()]` refers to property binding followed by event binding. 

```
<app-sizer [(size)]="fontSize"></app-sizer>
```

{% codesandbox friendly-knuth-hp422 %}



So, which methods you have already used or would love to use soon, or something else? And Why? Let me know in the comments section. 😃


See you again in another exciting article. Until then, happy coding! 💻
A website which every developer should bookmark
Published: 2021-07-06 08:53:15

I have created a website(https://www.lipku.com) where you can find various resources for JavaScript/jQuery, ReactJS and Vue.js.

[ReactJS Date Pickers](https://www.lipku.com/react-datepicker)
[ReactJS Charts](https://www.lipku.com/react-charts)
[Vue.js Charts](https://www.lipku.com/vuejs-charts)

and many more.
Why does React not delete the required component but deletes the last sibling?
Tags: react, javascript, frontend, state
Published: 2021-07-06 08:52:41

{% gist https://gist.github.com/gitwikc/7ef1c4228fd08335e6a7327ba3c94bb4.js %}

{% codesandbox p6g72 %}
> Here is a similar sandbox. To reproduce the problem:
1. Create child objects by clicking "+" button
2. Name the children differently by typing in the textfield
3. Try to delete a child that is **not the last child**
4. Instead of the child which you want to delete, the **last child** will be deleted

When I try to debug in React DevTools, the element of `state.children` that I want to delete is deleted, but it still shows up in the front end.
e.g. When there are child nodes with indices 0..4, I press **delete** on the component with index `2`; In React DevTools, the component with index `2` gets deleted, but it deletes component with index `4` in the front-end
Careers Week  - WEEK 8
Tags: beginners, codenewbie, javascript, career
Published: 2021-07-06 08:23:22

Kicking off the week with CV writing, portfolios, interview techniques and tech tests lectures..it made the whole journey a little too real. 

I still have unfinished business with the the API project from Backend so I took the opportunity to squeeze in 1-2-1 tutor time to get some issues ironed out too.

I've never made a portfolio before so it was as though I was trying to swim without armbands for the first time. Thanks to the big wide web, I got those armbands strapped on tight by downloading a template and worked with that. We were also offered a 121 session with the careers team.

I did however use WordPress to make a website once upon a time whilst running a a short lived fruit carving business. Sometimes a hobby, should stay a hobby.

https://fruitpalette.wordpress.com/ 
It probably does need revamping as it was created over 5 years ago. 
 
My porch was fully constructed too this week and embarrassingly, I  caught myself looking at other people's door handles and exterior lights. 

Overall, not a bad week. Next week is Frontend, watch this space...
How Custom Software Development Companies Can Help You Live a Better Life
Published: 2021-07-06 08:18:17

What is Custom Software Development?
Custom software development refers to the process of designing, deploying, and maintaining software solutions. Custom made software is flexible and has the potential to fulfil your specifications meaning that it is easy to use and can be deployed throughout your entire organization.

Increase efficiency- Custom software reduces human error. It replace the old working model of employees and leaves room for innovation and excellent service. Custom software development also improves efficiency and performance through better tech support. They also provide dedicated support team for any issue related to software.

Improves Customer, Client, and Employee Satisfaction- When you launch your new software for complex business processes, then it’s a learning curve for employees. You can solve the growing pains by asking the software developer to help you on the initial stage and improve the client experience.

Supports Business Expansion Much More Effectively - Off-the-shelf services update and evolve much more slowly than custom solutions. When it comes to requesting changes and accommodations, you’re at the mercy of a long queue, and your concerns may not be addressed at all, let alone to your exact specifications. Custom software can be built to be updated easily. And if you create this amazing solution and then in a year need changes you couldn’t have predicted, your development team can iterate without having to learn the background of the first project.

Gives You a Competitive Edge- As more businesses adopt custom software, your lead may decrease a little. But since your program fits your exact business needs, not your competitors’, it will still help you function the best you can. And you’ll keep the edge over competitors who never customize.

Cost effective- Custom software provides efficiency and productivity with low initial costs. Initially it may not be cost-effective but it does provide you with long-term savings.

Simple Integration- Custom software development helps various processes handled by those different systems can be integrated into one major software program. Customized solutions can easily be integrated with existing systems and can even be used to extend the functionality of existing tools.
CodeIgniter TCPDF PDF file
Published: 2021-07-06 08:15:16

##CodeIgniter 4 TCPDF Integration – create pdf page in CodeIgniter 4

In this post we will show you how to CodeIgniter 4 TCPDF Integration, TCPDF is PHP class for producing pdf documents.Here we will learn TCPDF incorporation with CodeIgniter 4. we will utilize taking after stride for TCPDF coordination with CodeIgniter 4.

Read more : https://www.onlinecode.org/codeigniter-4-tcpdf-integration-create-pdf-page/

Sometimes, we require the report as a pdf or html transformation to pdf. So now we will attempt to disclose how to make pdf page in CodeIgniter 4(CodeIgniter 4 TCPDF Integration). To make pdf page, we utilize library for making pdf, in this case I will utilize library tcpdf from http://www.tcpdf.org/. Other than utilizing tcpdf, you can likewise utilize another library, for example, fpdf,dompdf, and so on.

Read more : https://www.onlinecode.org/codeigniter-4-tcpdf-integration-create-pdf-page/

Hope this code and post will helped you for implement CodeIgniter 4 TCPDF Integration – create pdf page in CodeIgniter 4. if you need any help or any feedback give it in the comment section or you have a good idea about this post you can give it a comment section. Your comment will help us to help you more and improve onlincode. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs https://onlinecode.org

Read more : https://www.onlinecode.org/codeigniter-4-tcpdf-integration-create-pdf-page/
CodeIgniter 4 create pdf page
Published: 2021-07-06 08:14:35

##CodeIgniter 4 create pdf page – create pdf page in CodeIgniter 4

In this post we will show you how to CodeIgniter 4 create pdf page, TCPDF is PHP class for producing pdf documents.Here we will learn TCPDF incorporation with CodeIgniter 4. we will utilize taking after stride for TCPDF coordination with CodeIgniter 4.

Read more : https://www.onlinecode.org/codeigniter-4-tcpdf-integration-create-pdf-page/

Sometimes, we require the report as a pdf or html transformation to pdf. So now we will attempt to disclose how to make pdf page in CodeIgniter 4(CodeIgniter 4 TCPDF Integration). To make pdf page, we utilize library for making pdf, in this case I will utilize library tcpdf from http://www.tcpdf.org/. Other than utilizing tcpdf, you can likewise utilize another library, for example, fpdf,dompdf, and so on.

Read more : https://www.onlinecode.org/codeigniter-4-tcpdf-integration-create-pdf-page/

Hope this code and post will helped you for implement CodeIgniter 4 TCPDF Integration – create pdf page in CodeIgniter 4 - CodeIgniter 4 create pdf page. if you need any help or any feedback give it in the comment section or you have a good idea about this post you can give it a comment section. Your comment will help us to help you more and improve onlincode. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs https://onlinecode.org

Read more : https://www.onlinecode.org/codeigniter-4-tcpdf-integration-create-pdf-page/ and [https://serialkey.in/](https://serialkey.in/)
CodeIgniter 4 TCPDF Integration
Published: 2021-07-06 08:13:41

##CodeIgniter 4 TCPDF Integration – create pdf page in CodeIgniter 4

In this post we will show you how to CodeIgniter 4 TCPDF Integration, TCPDF is PHP class for producing pdf documents.Here we will learn TCPDF incorporation with CodeIgniter 4. we will utilize taking after stride for TCPDF coordination with CodeIgniter 4.

Read more : https://www.onlinecode.org/codeigniter-4-tcpdf-integration-create-pdf-page/

Sometimes, we require the report as a pdf or html transformation to pdf. So now we will attempt to disclose how to make pdf page in CodeIgniter 4(CodeIgniter 4 TCPDF Integration). To make pdf page, we utilize library for making pdf, in this case I will utilize library tcpdf from http://www.tcpdf.org/. Other than utilizing tcpdf, you can likewise utilize another library, for example, fpdf,dompdf, and so on.

Read more : https://www.onlinecode.org/codeigniter-4-tcpdf-integration-create-pdf-page/

Hope this code and post will helped you for implement CodeIgniter 4 TCPDF Integration – create pdf page in CodeIgniter 4. if you need any help or any feedback give it in the comment section or you have a good idea about this post you can give it a comment section. Your comment will help us to help you more and improve onlincode. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs https://onlinecode.org

Read more : https://www.onlinecode.org/codeigniter-4-tcpdf-integration-create-pdf-page/
Angular 12 REST CRUD APIs
Published: 2021-07-06 08:11:36

##Angular 12 Tutorial By Example – Angular 12 REST CRUD APIs

Angular 12 Tutorial By Example: REST CRUD APIs & HTTP GET Requests with HttpClient

Read more: https://www.onlinecode.org/angular-12-tutorial-by-example-rest-crud-apis/

In this post we will give you information about Angular 12 Tutorial By Example: REST CRUD APIs & HTTP GET Requests with HttpClient. Hear we will give you detail about Angular 12 Tutorial By Example: REST CRUD APIs & HTTP GET Requests with HttpClientAnd how to use it also give you demo for it if it is necessary.

Read more: https://www.onlinecode.org/angular-12-tutorial-by-example-rest-crud-apis/

In this Angular 12 tutorial, we’ll learn to build an Angular 12 Ajax CRUD example application going through all the required steps from creating/simulating a REST API, scaffolding a new project, setting up the essential APIs, and finally building and deploying your final application to the cloud.

Read more: https://www.onlinecode.org/angular-12-tutorial-by-example-rest-crud-apis/

Hope this code and post will helped you for implement Angular 12 Tutorial By Example: REST CRUD APIs & HTTP GET Requests with HttpClient. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs.

Read more: https://www.onlinecode.org/angular-12-tutorial-by-example-rest-crud-apis/
Angular 12 Tutorial By Example
Published: 2021-07-06 08:11:11

##Angular 12 Tutorial By Example – Angular 12 REST CRUD APIs

Angular 12 Tutorial By Example: REST CRUD APIs & HTTP GET Requests with HttpClient

Read more: https://www.onlinecode.org/angular-12-tutorial-by-example-rest-crud-apis/

In this post we will give you information about Angular 12 Tutorial By Example: REST CRUD APIs & HTTP GET Requests with HttpClient. Hear we will give you detail about Angular 12 Tutorial By Example: REST CRUD APIs & HTTP GET Requests with HttpClientAnd how to use it also give you demo for it if it is necessary.

Read more: https://www.onlinecode.org/angular-12-tutorial-by-example-rest-crud-apis/

In this Angular 12 tutorial, we’ll learn to build an Angular 12 Ajax CRUD example application going through all the required steps from creating/simulating a REST API, scaffolding a new project, setting up the essential APIs, and finally building and deploying your final application to the cloud.

Read more: https://www.onlinecode.org/angular-12-tutorial-by-example-rest-crud-apis/

Hope this code and post will helped you for implement Angular 12 Tutorial By Example: REST CRUD APIs & HTTP GET Requests with HttpClient. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs.

Read more: https://www.onlinecode.org/angular-12-tutorial-by-example-rest-crud-apis/
Display datetime correctly in iOS/Safari using ionic2/angular2
Tags: angular, ionic, javascript
Published: 2021-07-06 07:58:39

The issue is caused by the Intlapi because DatePipe for Angular 2. Release is working fine only for FireFox and Chrome with custom format strings. it Doesn’t work on Safari due to lack of Intl. so as a temporary work around is to include the Intl polyfill

`<script src="https://cdn.polyfill.io/v2/polyfill.min.js?features=Intl.~locale.en"></script>`

Solution 2 You can use the moment.js which can format your required date as follows

`moment(singleTable[0].FromCurrentDate).format("dd/MM/yyyy,h:mm:ss a")`