Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Ti Ext Coupons Laravel Package

tastyigniter/ti-ext-coupons

TastyIgniter Coupons extension adds fixed or percentage discounts with advanced rules like minimum spend, day/time limits, and location targeting. Create time-sensitive or seasonal promotions to boost sales and reward customers.

View on GitHub
Deep Wiki
Context7

Getting Started

Install the package via Composer:

composer require vendor/package-name

Publish the migration and config files if needed:

php artisan vendor:publish --provider="Vendor\PackageName\PackageServiceProvider"

The package now uses the Location class directly in the coupon model. To create a coupon with location data, use:

$coupon = Coupon::create([
    'code' => 'SAVE20',
    'discount' => 20,
    'location' => new \Vendor\PackageName\Models\Location(/* params */)
]);

Check the updated Coupon model for the latest API.


Implementation Patterns

Direct Location Integration

The coupon model now accepts a Location object directly instead of a serialized string or array. This simplifies workflows where location data is already instantiated:

// Before (v4.1.2 or earlier)
$coupon->location = ['lat' => 40.7128, 'lng' => -74.0060];

// After (v4.1.3+)
$location = new \Vendor\PackageName\Models\Location(40.7128, -74.0060);
$coupon->location = $location;

Querying by Location

Leverage the new Location class for spatial queries:

// Find coupons near a point
$nearbyCoupons = Coupon::whereLocationNear(new \Vendor\PackageName\Models\Location(34.0522, -118.2437), 5)
                      ->get();

Migration Updates

If you’ve customized migrations, update them to use the Location class:

// Old (deprecated)
$table->text('location_data')->nullable();

// New (recommended)
$table->json('location_data')->nullable(); // If using JSON serialization internally

Gotchas and Tips

Breaking Change: Serialization Format

The internal representation of location_data has changed. If you rely on raw database queries or custom serialization:

  • Fix: Use the Location class methods (e.g., toArray(), toJson()) instead of direct DB access.
  • Debug: Check for JSON_EXCEPTION or INVALID_ARGUMENT errors when loading old data.

Performance Tip: Hydrate Locations Lazily

Avoid instantiating Location objects prematurely. Use accessors:

// Good: Lazy loading
$coupon->location->getCoordinates();

// Bad: Eager loading (if not needed)
$location = $coupon->location; // Triggers full hydration

Extending the Location Class

Customize the Location class by extending it:

class CustomLocation extends \Vendor\PackageName\Models\Location {
    public function isInServiceArea() {
        return $this->distanceTo(new Location(/* service center */)) < 10;
    }
}

Override the coupon model’s setLocationAttribute if needed:

protected function setLocationAttribute($value) {
    $this->attributes['location_data'] = $value instanceof Location
        ? $value->toJson()
        : json_encode($value);
}

Deprecation Note

The old Coupon::setLocationData() method is deprecated. Use:

// Old (deprecated)
Coupon::setLocationData($coupon, ['lat' => 1, 'lng' => 2]);

// New
$coupon->location = new Location(1, 2);
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
codifyo/ts-generator-bundle
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky
spatie/mailcoach-vapor