PHP code example of bastuijnman / flagpost

1. Go to this page and download the library: Download bastuijnman/flagpost 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/ */

    

bastuijnman / flagpost example snippets



 
namespace App\Http\Controllers;
 
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Laravel\Pennant\Feature;
use Bastuijnman\Flagpost\Goal;
 
class PodcastController
{
    /**
     * Display a listing of the resource.
     */
    public function index(Request $request): Response
    {
        return Feature::active('new-api')
                ? $this->resolveNewApiResponse($request)
                : $this->resolveLegacyApiResponse($request);
    }

    public function listen(Request $request): Response
    {
        Goal::reached('new-api');
        // Return response
    }
 
    // ...
}

Goal::for($team)->reached('billing-v2');

$results = Goal::results('purchase-button');
/*
 * 
 * [ 
 *   [ 'value' => 'total', 'converted' => 39 ], 
 *   [ 'value' => 'blue-sapphire', 'converted' => 17 ], 
 *   [ 'value' => 'seafoam-green', 'converted' => 13 ],
 *   [ 'value' => 'tart-orange', 'converted' => 9 ] 
 * ]
 * 
 */

$timeseries = Goal::timeseries('purchase-button', CarbonInterval::hour());
/*
 * 
 * [
 *   'blue-sapphire' => [
 *     [ 'time' => 1706706000, 'converted' => 3 ],
 *     [ 'time' => 1706706300, 'converted' => 2 ],
 *     [ 'time' => 1706706600, 'converted' => 0 ],
 *     ...
 *   ],
 *   'seafoam-green' => [
 *     [ 'time' => 1706706000, 'converted' => 1 ],
 *     [ 'time' => 1706706300, 'converted' => 3 ],
 *     [ 'time' => 1706706600, 'converted' => 2 ],
 *     ...
 *   ],
 *   'tart-orange' => [
 *     [ 'time' => 1706706000, 'converted' => 0 ],
 *     [ 'time' => 1706706300, 'converted' => 2 ],
 *     [ 'time' => 1706706600, 'converted' => 5 ],
 *     ...
 *   ],
 * ]
 * 
 */

$timeseries = Goal::timeseries('purchase-button', CarbonInterval::hours(8), 3600);
bash
php artisan migrate