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.
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.
Location IntegrationThe 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;
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();
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
The internal representation of location_data has changed. If you rely on raw database queries or custom serialization:
Location class methods (e.g., toArray(), toJson()) instead of direct DB access.JSON_EXCEPTION or INVALID_ARGUMENT errors when loading old data.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
Location ClassCustomize 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);
}
The old Coupon::setLocationData() method is deprecated. Use:
// Old (deprecated)
Coupon::setLocationData($coupon, ['lat' => 1, 'lng' => 2]);
// New
$coupon->location = new Location(1, 2);
How can I help you explore Laravel packages today?