generated from spatie/package-skeleton-laravel
-
-
Notifications
You must be signed in to change notification settings - Fork 1
01. How to use
Luca Longo edited this page Aug 10, 2020
·
1 revision
You can install the package via composer:
composer require masterix21/laravel-addressable
Next, you must publish the migrations files and the config
php artisan vendor:publish --provider "Masterix21\Addressable\AddressableServiceProvider"
The package has three built-in traits: HasAddresses
, HasBillingAddresses
and HasShippingAddresses
.
It's the standard trait that will implement addresses with indistinct functionality.
use Masterix21\Addressable\Models\Concerns\HasAddresses;
class User {
use HasAddresses;
}
// Retrieve all user's addresses
$user = User::with(['addresses'])->first();
It will implement the supports for the billing addresses.
use Masterix21\Addressable\Models\Concerns\HasBillingAddresses;
class User {
use HasBillingAddresses;
}
// Retrieve all user's billing addresses
$user = User::with(['billingAddresses'])->first();
// or the billing address marked as primary
$user = User::with(['billingAddress'])->first();
It will implement the supports for the shipping addresses.
use Masterix21\Addressable\Models\Concerns\HasShippingAddresses;
class User {
use HasShippingAddresses;
}
// Retrieve all user's shipping addresses
$user = User::with(['shippingAddresses'])->first();
// or the shipping address marked as primary
$user = User::with(['shippingAddress'])->first();