1. Go to this page and download the library: Download youcanshop/foggle 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/ */
youcanshop / foggle example snippets
namespace App\Providers;
use App\Models\User;
use Illuminate\Support\ServiceProvider;
class AppServiceProvider extends ServiceProvider
{
public function boot(): void
{
foggle()->define('themes', fn (User $user) => match (true) {
$user->isTeamMember() => true,
$user->isTestUser() => false,
default => false,
});
}
}
namespace App\Features;
use App\Models\User;
use Illuminate\Support\Lottery;
class NewApi
{
public function resolve(User $user): mixed
{
return match (true) {
$user->isInternalTeamMember() => true,
$user->isHighTrafficCustomer() => false,
default => Lottery::odds(1 / 100),
};
}
}
function are_themes_active() {
return foggle()->active('themes');
}
function are_themes_inactive(User $user) {
return foggle()->for($user)->inactive('themes');
}
foggle()->cFlush()
namespace App\ContextResolvers;
use App\Services\StoreService;
use YouCanShop\Foggle\Contracts\ContextResolver;
class StoreResolver implements ContextResolver {
public function __construct(private readonly StoreService $storeService)
{
}
public function resolve(): ?Store
{
return $this->storeService->getCurrentStore();
}
}
namespace App\Models;
use FlagRocket\FlagRocketUser;
use Illuminate\Database\Eloquent\Model;
use YouCanShop\Foggle\Contracts\Foggable;
class User extends Model implements Foggable
{
public function foggleId(): string
{
return $this->id;
}
}