All packages
Addresses for Laravel
Custom address model
Extend the package model and point the config at your subclass:
namespace App\Models;
use Illuminate\Database\Eloquent\Builder;
use RoundlyConsulting\Addresses\Address as BaseAddress;
class Address extends BaseAddress
{
protected $table = 'addresses';
public function scopeInCity(Builder $query, string $city): void
{
$query->where('city', $city);
}
}// config/addresses.php
'model' => \App\Models\Address::class,The trait’s relation, the builder, the actions and the facade all resolve the model through config, so your class is created, queried and returned everywhere. It inherits the scopes, casts, the addressable relation, formatted(), the primary-address handling, soft deletes and the AddressDeleted dispatch:
use RoundlyConsulting\Addresses\Facades\Addresses;
$customer->addresses()->inCity('Bratislava')->get(); // your scope, on the package relation
Addresses::for($customer)->primary(); // returns an App\Models\AddressRules
- The class must be RoundlyConsulting\Addresses\Address or extend it. Anything else — an Eloquent model that does not extend it, or a value that is not a model class at all — throws the package toolkit’s InvalidConfigurationException naming the key; a foreign class is never silently replaced by the packaged model.
- Set protected $table = 'addresses' — Eloquent derives the table from the class name, so a subclass with any other name would look for a different table.
Show your open-source love
This package is free and MIT-licensed. If it saves you time, a one-off donation or a Patreon membership keeps it maintained, tested and documented.
More ways to support, including cryptoBy donating, you agree to our donation terms.
Want this built into your product?
We integrate our packages into custom Laravel and AI builds. Tell us what you're working on and we'll reply within 48 hours.