Using the new Upserts feature in the Laravel Query Builder

Using the new Upserts feature in the Laravel Query Builder

When to use eloquent upserts

You’ve probably come across a situation before where you needed to do some kind of mass update or sync with external data. A naive way you might approach this could be similar to below.

collect($csvContacts)->each(function (array $row) {
    $contact = Contact::updateOrCreate(
        ['email' => $row['email']],
        ['name' => $row['name'], 'address' => $row['address']]

Under the hood, this will make 2 queries for each record. First, it will find the first row matching all of the key/value pairs in the first array. If a row already exists, it will update it, otherwise a new row is inserted.

With small imports this will work fine, but imagine you had 100,000 rows in your CSV. This would result in 200,000 queries, which is going to take forever.

Using Upserts

When using upserts a single query is made containing all the rows. This query includes on duplicate key update on MySQL and on conflict ... do update set on Postgres which instructs the database to update records if they already exist in the database.

It’s important to note that you must have either a primary or unique index on the column you are upserting so the database. If you forget to add the index you’ll get an error.

Obviously, making a single query is much more efficient and lets the database internally compute duplicate rows (which is very quick since you have an index on the column).

It’s also a good idea to chunk these queries into blocks, especially if your queries are inserting/updating lots of data. If you don’t do this, you may hit query size limits on some databases.

    ->map(function (array $row) {
        return Arr::only($row, ['email', 'name', 'address']);
    ->each(function (Collection $chunk) {
        Contact::upsert($chunk, 'email');

Additional Reading

Framework PR


via Laravel News Links

October 25, 2020 at 08:18PM

Integrate PayPal Plus on Laravel 8

Integrate PayPal Plus on Laravel 8

If you are interested to integrate PayPal plus with Laravel 8, this tutorial will help you a lot. Today, I will guide you on how to integrate PayPal Plus with Laravel. Let’s get started.


PayPal Account

You need to have a Paypal account in order to process.

Create Sandbox Accounts.

Navigate to Sandbox > Accounts then click on the blue color Create Account button.
On the popup box, set

  • Account Type: Business
  • Country: Brazil

Create Sandbox App

Navigate to Sandbox > My Apps & Credentials click on the blue color Create App button.
In the form,

  • Set an app name. It can be anything you want.
  • Choose newly created sandbox business email.

Get APP Credentials

Once you have done successfully, navigate to the newly created app. You should able to see Client ID and Client Secret for the app.

Generate Fake Credit Card

Navigate to Mock > Credit Card Generator and then create a credit card. It will give you a card number, expired date and CVV.

Laravel Integration

Let’s dig into laravel application now.

Step 1: Define Routes:

Go to web.php file and define a GET route /paypal.

Route::get('paypal', [PayPalController::class, 'index']);

Step 2: Create Controller:

Now let’s create a controller called PayPalController.

php artisan make:controller PayPalController

In the index() method, first, let’s send a request for creating the payment request as described in the documentation

    public function index()
        $clientId = "PayPal Private Key";
        $secret = "PayPal Public Key";

        // Get Bearer Token
        $ch = curl_init();

        curl_setopt($ch, CURLOPT_URL, "");
        curl_setopt($ch, CURLOPT_HEADER, false);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_SSLVERSION , 6);
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
        curl_setopt($ch, CURLOPT_USERPWD, $clientId.":".$secret);
        curl_setopt($ch, CURLOPT_POSTFIELDS, "grant_type=client_credentials");

        $token = json_decode(curl_exec($ch), true);
        $bearerToken = $token['access_token'];

        $total = 121;

        $postData = [
            'intent' => 'sale',
            'payer' => [
                'payment_method' => 'paypal',
                'transactions' => [
                    0 => [
                        'amount' => [
                            'currency' => 'BRL',
                            'total' => $total,
                            'details' => [
                                'shipping' => '0',
                                'subtotal' => $total,
                                'shipping_discount' => '0.00',
                                'insurance' => '0.00',
                                'handling_fee' => '0.00',
                                'tax' => '0.00',
                    'description' => 'This is the payment transaction description',
                    'payment_options' => [
                        'allowed_payment_method' => 'IMMEDIATE_PAY',
                    'item_list' => [
                        'shipping_address' => [
                            'recipient_name' => 'PP Plus Recipient',
                            'line1' => 'Gregório Rolim de Oliveira, 42',
                            'line2' => 'JD Serrano II',
                            'city' => 'Votorantim',
                            'country_code' => 'BR',
                            'postal_code' => '18117-134',
                            'state' => 'São Paulo',
                            'phone' => '0800-761-0880',
                        'items' => [
                            0 => [
                                'name' => 'handbag',
                                'description' => 'red diamond',
                                'quantity' => '1',
                                'price' => $total,
                                'tax' => '0',
                                'sku' => 'product34',
                                'currency' => 'BRL',
            'redirect_urls' => [
                'return_url' => '',
                'cancel_url' => '',

        // Send request for Permission
        $ch = curl_init();

        curl_setopt($ch, CURLOPT_URL, '');
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($postData));

        $headers = array();
        $headers[] = 'Content-Type: application/json';
        $headers[] = 'Authorization: Bearer ' . $bearerToken;
        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

        $result = curl_exec($ch);
        if (curl_errno($ch)) {
            echo 'Error:' . curl_error($ch);

       $paymentData = json_decode($result, true);

       return view("paypal-plus")
            ->with('paymentData', $paymentData);

Create a view page

Now, let’s create a view page called resources/views/paypal-plus.blade.php for rendering the paypal form.

    <script src="" type="text/javascript">

    <div id="ppplus"></div>

    <input type="hidden" id="paypal_approval_url" value="">
    <input type="hidden" id="paypal_payment_id" value="">

    <script type="application/javascript">
        var approvalUrl = document.getElementById('paypal_approval_url').value;
        var paymentId = document.getElementById('paypal_payment_id').value;

        var ppp = PAYPAL.apps.PPP({
            "approvalUrl": approvalUrl,
            "placeholder": "ppplus",
            "mode": "sandbox",
            "payerEmail": "[email protected]",
            "payerFirstName": "Thouhedul",
            "payerLastName": "Islam",
            "payerTaxId": "424.159.708-40",
            "country": "BR",
            "collectBillingAddress": false,
            onContinue: function (rememberedCards, payerId, token, term) {
                window.location = ''
                    + rememberedCards 
                    + '&payerId=' + payerId
                    + '&token=' + token
                    + '&term=' + term
                    + '&paymentId=' + paymentId;

        onclick="ppp.doContinue(); return false;"> Checkout

Note here, I have set a redirect location once user submit the form. So, let’s define a new route for that.

Define route for redirect location

Route::get('paypal-approval', [PayPalController::class, 'post']);

Create Post Method

To process, let’s create a method called post().
$clientId = “PayPal Public ID”;
$secret = “PayPal Private ID”;

    public function post()
        $payerId = request()->payerId;
        $rememberedCards = request()->rememberedCards;
        $token = request()->token;
        $paymentId = request()->paymentId;

        $clientId = "PayPal Private Key";
        $secret = "PayPal Public Key";

        // Get Bearer Token
        $btCh = curl_init();

        curl_setopt($btCh, CURLOPT_URL, "");
        curl_setopt($btCh, CURLOPT_HEADER, false);
        curl_setopt($btCh, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($btCh, CURLOPT_SSLVERSION , 6);
        curl_setopt($btCh, CURLOPT_POST, true);
        curl_setopt($btCh, CURLOPT_RETURNTRANSFER, true); 
        curl_setopt($btCh, CURLOPT_USERPWD, $clientId.":".$secret);
        curl_setopt($btCh, CURLOPT_POSTFIELDS, "grant_type=client_credentials");

        $token = json_decode(curl_exec($btCh), true);
        $bearerToken = $token['access_token'];

        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, "$paymentId/execute");
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, "{\n  \"payer_id\": \"$payerId\"\n}");

        $headers = array();
        $headers[] = 'Content-Type: application/json';
        $headers[] = 'Authorization: Bearer ' . $bearerToken;
        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

        $result = curl_exec($ch);

        if (curl_errno($ch)) {
            echo 'Error:' . curl_error($ch);


        return $approvedData = json_decode($result, true);


Now let’s test the fake card that we have generated earlier. Now, you have to put card number, expired date, CVV and put any name. Once done, submit the form.

If everything goes smoothly, you will get some data like this. Where you will get "state": "approved" and should have "id": "PAYID-L6HGX3A4MT388022P233113E".

BTW, if you need to show any thank you page, then you can do operation based on state and id on the condition.

    "id": "PAYID-L6HGX3A4MT388022P233113E",
    "intent": "sale",
    "state": "approved",
    "cart": "66099532VT8552054",
    "payer": {
        "payment_method": "paypal",
        "status": "UNVERIFIED",
        "payer_info": {
            "email": "[email protected]",
            "first_name": "John",
            "last_name": "Doe",
            "payer_id": "CC3S9AQAUZH62",
            "shipping_address": {
                "recipient_name": "PP Plus Recipient",
                "line1": "Gregório Rolim de Oliveira, 42",
                "line2": "JD Serrano II",
                "city": "Votorantim",
                "state": "São Paulo",
                "postal_code": "18117-134",
                "country_code": "BR",
                "normalization_status": "UNKNOWN"
            "tax_id_type": "BR_CPF",
            "tax_id": "42415970840",
            "country_code": "BR"

Hope this post will be helpful for you.


via Laravel News Links

October 25, 2020 at 08:18PM

Composer 2.0 is now released with performance improvements

Composer 2.0 is now released with performance improvements

Composer 2.0 is now released and it comes with many changes and performance improvements.

The post Composer 2.0 is now released with performance improvements appeared first on Laravel News.

Join the Laravel Newsletter to get Laravel articles like this directly in your inbox.


via Laravel News

October 24, 2020 at 04:52PM

How to force restart your iPhone 12 or iPhone 12 Pro

How to force restart your iPhone 12 or iPhone 12 Pro

The iPhone 12 and iPhone 12 Pro may be high performance, but that won’t stop the occasional need to force restart your mobile device. Here’s the steps you need to reboot your iPhone 12 if a graceful shutdown isn’t possible.

While it is entirely possible for some iPhone users to never need to turn off or restart their device at all, the vast majority of users will at some point need to do so. Maybe an app hung in such a way that iOS can’t handle, or the iPhone stops responding to touches and individual button presses.

In such situations, the best course of action is to restart your iPhone, but even that may not be immediately possible, such as if the screen isn’t responding to touch input, preventing you from performing the final swipe to power it off. Even in this scenario, you can still forcefully restart the device.

This guide will take you through the usual way of turning off your iPhone, and then to do the forced restart. It is usually advisable to go for the first method, but the second is also useful as it is a generally quicker process to reboot, and far more likely to work.

These methods cover practically all models that use Face ID as their biometric authentication system, from the iPhone X to modern models including the iPhone 12 and iPhone 12 Pro. It can even be used on iPad models that use Face ID, such as the current-generation iPad Pro, with the force restart method even able to be used on the iPhone 8 and iPhone 8 Plus.

Most earlier models have different techniques to force a restart, typically relying on a press of the Home button. Its removal forced Apple to come up with a newer procedure for the iPhone X, which it has continued to use ever since.

How to turn the iPhone 12 off then on again

  • Hold down both the volume up and side buttons at the same time for a few seconds.
  • Press the on-screen power symbol at the top of the screen and slide it to the right.
  • To turn it back on, hold the side button until the Apple logo appears.

This method performs a graceful shutdown of the iPhone, followed by the standard turn-on procedure. This is the method you should be trying to accomplish first.

In the event that you cannot use the iPhone’s touchscreen, step two of that list will not be possible to complete. This is why there is a method to forcefully restart the device.

How to force restart the iPhone 12 and iPhone 12 Pro

  • Press and very quickly release the volume up button, followed by the volume down button.
  • Press and hold down the side button.
  • When the Apple logo appears, release the side button.

While this method will attempt to restart your iPhone, it may not necessarily fix the problem. Apple’s support pages offer further advice if the iPhone won’t turn back on, including how to restore the device in more serious cases.

Forcing a restart on iPhone 12 Pro

As a word of warning, make sure to pay attention when you are restarting your iPhone, and follow all instructions properly. This is specifically the case if you confuse the two sets of instructions and end up holding down the volume up and side buttons for a prolonged period of time.

Doing so will start a five-second countdown for the Emergency SOS function, where it will count down from five and vibrate for each number, as the Emergency SOS slider fills up. On reaching 0 while still holding both buttons down, the iPhone will consider the bar full and dial the emergency services, which may prompt the police or an ambulance visit to your location.

Just remember to pay attention and to release the buttons if the vibration and countdown starts.


via AppleInsider

October 23, 2020 at 02:33PM

How to Customize Your iPhone Home Screen

How to Customize Your iPhone Home Screen

At long last, iPhone owners can finally customize their home screens with widgets. (Android users, feel free to skip—y’all have had this feature for years.) After you install iOS 14, you can deck out your iPhone with fresh icons, wallpaper, and widgets for a fully personalized look. Here’s how to get started.

First, you’ll need some new app icons. You can find some online by searching for iPhone icon packs, or by visiting a site like Save the icons to your camera roll.

Then head on over to the App Store and download Widgetsmith, which lets you change your iPhone’s fonts and colors, and Apple’s Shortcuts app (if you don’t already have it), which is where things start to get a little…. complicated.

You have to create shortcuts from your new app icons to the apps themselves. Within the Shortcuts app, hit the plus sign in the top right corner. Then tap Add Action and select Scripting. From there, choose the Open App command, then pick the app you want to open. Hit the three dots and select Add to Home Screen. From here, write the name of the app and hit the icon picture to the left. Select the Choose Photo option to open up your Camera Roll and select that icon you chose for this particular app in step one. Unfortunately, you have to repeat this process for every new app icon. To get rid of the old app icons, long-press your home screen to send them to the App Library.

Creating shortcuts from new icons to apps will slow down app loading times and also prevent you from viewing notification badges. And, as you can see from the video above, this process is time-consuming, to say the least. But if you want your iPhone to reflect your true spirit, it might be worth the hours it takes to fully trick out your home screen. Don’t say we didn’t warn you!


via Gizmodo

October 23, 2020 at 03:51PM

Use Livewire With Blade Components

Use Livewire With Blade Components

It’s usually a good idea to extract reusable bits of code into blade components. Let’s spend some time to extract a livewire text input component and use “whereStartsWith” to get our wire:model attribute even when it has a modifier.
View the source code for this episode on [GitHub](


via Laracasts

October 23, 2020 at 10:32AM

Apple University VP takes an in-depth look at how Apple is ‘organized for innovation’

Apple University VP takes an in-depth look at how Apple is ‘organized for innovation’

Apple University Vice President and Dean Joel Podolny has penned an article that takes a deep dive into how Apple is structured and how it’s unique among large businesses.

The in-depth review of Apple’s structure, published Thursday in Harvard Business Review, was co-written by Apple University faculty member Morten Hansen. And it offers an interesting look at how the Cupertino tech giant is “organized for innovation.”

Podolny opens by noting how much Apple has grown. In 1997, when Steve Jobs returned to the company, Apple had 8,000 employees and about $7 billion in annual revenue. Fast forward to 2019, and the company has 137,000 staffers and brings in about $260 billion in revenue.

But amid all of that growth, Apple has largely kept the same centralized organizational structure that Jobs implemented in 1997.

“Believing that conventional management had stifled innovation, Jobs, in his first year returning as CEO, laid off the general managers of all the business units (in a single day), put the entire company under one P&L, and combined the disparate functional departments of the business units into one functional organization,” Podolny wrote.

The Apple University VP notes that most large companies have decentralized or multi-division organizational structures. Apple, then, is proof that a centralized system can be functional for a business this size, they added.

Of course, the two writers note that a lot has still changed in the more than two decades between 1997 and 2019. “Apple relies on a structure that centers on functional expertise. Its fundamental belief is that those with the most expertise and experience in a domain should have decision rights for that domain,” the piece continues.

“This is based on two views: First, Apple competes in markets where the rates of technological change and disruption are high, so it must rely on the judgment and intuition of people with deep knowledge of the technologies responsible for disruption. Long before it can get market feedback and solid market forecasts, the company must make bets about which technologies and designs are likely to succeed in smartphones, computers, and so on. Relying on technical experts rather than general managers increases the odds that those bets will pay off.”

The piece also details three leadership qualities that Apple looks for in a candidate, which has been applied for Apple managers at every level since Jobs first adopted the organization.

They include: “deep expertise that allows them to meaningfully engage in all the work being done within their individual functions; immersion in the details of those functions; and a willingness to collaboratively debate other functions during collective decision-making. When managers have these attributes, decisions are made in a coordinated fashion by the people most qualified to make them.”

Podolny and Hansen write that Apple’s business structure is uncommon. And although it includes some risks not seen with decentralized models, it can offer “extraordinary results” for companies that adopt it.

“[Apple’s organization] flies in the face of prevailing management theory that companies should be reorganized into divisions and business units as they become large. But something vital gets lost in a shift to business units: the alignment of decision rights with expertise,” the piece reads.

Despite some of the hurdles that companies may see when attempting to adopt a model similar to Apple’s, Podolny notes that the shift could be done in intermediate steps — and, after it’s complete, may be well worth the effort. “Apple’s track record proves that the rewards may justify the risks. Its approach can produce extraordinary results,” Podolny concludes.

The full piece goes into further depth and offers more detailed examples of Apple’s organizational structure, and is well worth a read.


via AppleInsider

October 22, 2020 at 03:51PM

Narf! Yakko, Wakko, and Dot are back in first trailer for Animaniacs reboot

Narf! Yakko, Wakko, and Dot are back in first trailer for Animaniacs reboot

Yakko, Wakko, and Dot are back in Hulu’s reboot of the classic Animaniacs cartoon.

Readers of a certain age will have fond childhood memories of weekday afternoons spent in the company of the Warner siblings, Yakko, Wakko, and Dot, the central figures of the hugely popular, Emmy-award winning animated series, Animaniacs. Now a whole new generation can appreciate their comic genius with Hulu’s revival of the show, slated to debut next month.

The premise of the original Animaniacs was that Yakko, Wakko, and Dot were characters from the 1930s who were locked way in a water tower on the Warner Bros. lot until they escaped in the 1990s. Now they exist to wreak havoc and have fun. The format borrowed heavily from sketch comedy, with each episode typically featuring three short mini-episodes centered on different characters, connected by bridging segments. Other regular characters included two genetically altered lab mice, Pinky and the Brain, who are always trying to take over the world; Ralph the Security Guard; Slappy Squirrel and her nephew, Skippy; Chicken Boo; Flavio and Marita, aka the Hip Hippos; studio psychiatrist Dr. Otto Scratchansniff and Hello Nurse (also a common catchphrase); and a trio of pigeons known as The Goodfeathers.

As appealing to adults as to kids, the show was smart, funny, irreverent, and even educational, especially with its playful songs listing the nations of the world, for instance, or all the US states and their capitals—set to the tune of “Turkey in the Straw”—or all the presidents set to the “William Tell Overture.” (My personal favorite was “The Solar System Song,” complete with the obligatory joke about Uranus.) The writers were masters of parody, so much so that it became something of a badge of honor to be so featured. Honorees included A Hard Day’s Night, Seinfeld, Friends, Bambi, Power Rangers, Rugrats, and The Lion King, as well as the Gilbert and Sullivan comic operas Pirates of Penzance and H.M.S. Pinafore. And of course, the Goodfeathers segments invariably parodied characters from both The Godfather and Goodfellas.

When the original series began streaming on Netflix, it proved so popular that Steven Spielberg’s Amblin Television and Warner Bros. Animation began thinking about reviving Animaniacs. They ultimately inked a deal with Hulu, which included the rights for the original series, as well as Tiny Toon Adventures, Pinky and the Brain, and Pinky, Elmyra, and the Brain. (That means we can all revisit our favorites on Hulu.) Spielberg returned as executive producer and insisted on bringing back most of the original voice cast for the reboot. A first-look clip debuted earlier this month at the virtual New York Comic-Con (embedded below), parodying Jurassic Park (John Hammond—or rather, a cartoon Spielberg channeling Hammond—reanimates the Warner siblings).

  • Yakko, Wakko, and Dot are happy to sell out to Hulu reboot… for the right price.

  • “You should see our new contracts!”


  • Resurrected and ready for their close-up.


  • The Warner siblings learn about all the new tech they’ve missed out on.


  • “Quantum mechanics. Quinoa wraps. We’ve missed so much!”

  • Meanwhile, at Acme Labs….


  • “Gee, Brain, what do you want to do tonight?”


  • “The same thing we do every night, Pinky. Try to take over the world!”


  • The show’s gleefully absurdist humor appears to be intact.


  • “Oh, sounds like an Odyssey!”


  • “Less talky, more flappy.”


  • Blast from the past.


  • The Brain has a cunning plan.


  • They’re totally insaney.


Per the official summary:

They’re back! The Warner brothers, Yakko and Wakko, and the Warner sister Dot, have a great time wreaking havoc and mayhem in the lives of everyone they meet. After returning to their beloved home, the Warner Bros. water tower, the siblings waste no time in causing chaos and comic confusion as they run loose through the studio, turning the world into their personal playground. Joining Yakko, Wakko and Dot, fan-favorite characters Pinky and the Brain also return to continue their quest for world domination.

The trailer showcases the same irreverently goofy attitude of the original, with the Warners not above poking fun at themselves—in this case, denouncing reboots as being  ”symptomatic of a fundamental lack of originality in Hollywood.” But they gleefully change their tune when Hulu presents them with a big check for the Animaniacs reboot (“You sellouts!”).  Cue the classic Animaniacs theme song with cheeky new lyrics (“It’s time for Animaniacs/You should see our new contracts!”). After being off the air for so long, the Warner siblings have a lot of catching up to do, particularly when it comes to the latest technology. And Pinky and the Brain make a welcome appearance, with Pinky fretting over an online dating app.

All in all, it looks like a promising revival. The new Animaniacs debuts on Hulu on November 20, 2020.

Animaniacs clip parodying Jurassic Park.

Listing image by YouTube/Hulu


via Ars Technica

October 21, 2020 at 08:19PM

Amazon Launches Program To Pay Consumers For Their Data On Non-Amazon Purchases

Amazon Launches Program To Pay Consumers For Their Data On Non-Amazon Purchases

An anonymous reader quotes a report from TechCrunch: Amazon has launched a new program that directly pays consumers for information about what they’re purchasing outside of and for responding to short surveys. The program, Amazon Shopper Panel, asks users to send in 10 receipts per month for any purchases made at non-Amazon retailers, including grocery stores, department stores, drug stores and entertainment outlets (if open), like movie theaters, theme parks and restaurants. Amazon’s own stores, like Whole Foods, Amazon Go, Amazon Four Star and Amazon Books do not qualify.
Program participants will take advantage of the newly launched Amazon Shopper Panel mobile app on iOS and Android to take pictures of paper receipts that qualify or they can opt to forward emailed receipts to to earn a $10 reward that can then be applied to their Amazon Balance or used as a charitable donation. Amazon says users can then earn additional rewards each month for every survey they complete. The optional surveys will ask about brands and products that may interest the participant and how likely they are to purchase a product. Other surveys may ask what the shopper thinks of an ad. These rewards may vary, depending on the survey. The program is currently opt-in and invite-only for U.S. consumers only.
The report also notes that Amazon "will delete any sensitive information from the receipts users upload, like prescription information." Importantly, Amazon "doesn’t delete users’ personal information, instead storing it in accordance with its existing Privacy Policy. It will allow users to delete their previously uploaded receipts, if they choose."

Read more of this story at Slashdot.


via Slashdot

October 21, 2020 at 09:14AM

Livewire Charts

Livewire Charts

Livewire Charts is a package by Andrés Santibáñez for creating neat charts using Livewire in Laravel projects.

This package uses the following technologies (required) to generate Livewire charts:

  • Laravel Livewire v2
  • Alpine JS
  • Apex Charts

Once you have those requirements installed and set up, here’s how easy it can be to create a chart with this package on the backend:

$columnChartModel = (new ColumnChartModel())
    ->setTitle('Expenses by Type')
    ->addColumn('Food', 100, '#f6ad55')
    ->addColumn('Shopping', 200, '#fc8181')
    ->addColumn('Travel', 300, '#90cdf4')

Then on the frontend, you pass the variable to blade:


The code above are examples taken directly from the readme. Using the example code, you would have a chart that looks like the following:

At the time of writing, livewire-charts supports three types of charts:

  • Line chart
  • Column chart (as seen above)
  • Pie Chart

You can also enable interactions and provide listeners that will fire in Livewire components, along with the ability to make charts reactive. Be sure to check out the livewire-charts readme for full details on usage.

Learn More

You can learn more about this package, get full installation instructions, and view the source code on GitHub at asantibanez/livewire-charts. Andrés also has a Livewire Charts demo app with examples.

Filed in:


via Laravel News

October 20, 2020 at 09:41AM