PHP code example of knackline / laravel-toon

1. Go to this page and download the library: Download knackline/laravel-toon library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

knackline / laravel-toon example snippets


use Knackline\LaravelToon\Toon;

$jsonData = [
    "context" => [
        "task" => "Our favorite hikes together",
        "location" => "Boulder",
        "season" => "spring_2025"
    ],
    "friends" => ["ana", "luis", "sam"],
    "hikes" => [
        [
            "id" => 1,
            "name" => "Blue Lake Trail",
            "distanceKm" => 7.5,
            "elevationGain" => 320,
            "companion" => "ana",
            "wasSunny" => true
        ]
    ]
];

$toon = Toon::fromJson($jsonData);

$toonString = "context:
  task: Our favorite hikes together
  location: Boulder
  season: spring_2025
friends[3]: ana,luis,sam
hikes[3]{id,name,distanceKm,elevationGain,companion,wasSunny}:
  1,Blue Lake Trail,7.5,320,ana,true
  2,Ridge Overlook,9.2,540,luis,false";

$jsonData = Toon::toJson($toonString);

use Knackline\LaravelToon\Facades\Toon;

$toon = Toon::fromJson($data);
$json = Toon::toJson($toon);