PHP code example of stylers / laravel-address

1. Go to this page and download the library: Download stylers/laravel-address 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/ */

    

stylers / laravel-address example snippets


use Stylers\Address\Contracts\Models\Traits\HasAddressesInterface;
use Stylers\Address\Models\Traits\HasAddresses;

class User extends Authenticatable implements HasAddressesInterface
{
    use Notifiable;
    use HasAddresses;
}

use Stylers\Address\Enums\AddressTypeEnum;

$user = User::first();
$attributes = [
    "country" => "Hungary",
    "zip_code" => "1055",
    "city" => "Budapest",
    "name_of_public_place" => "Kossuth Lajos",
    "type_of_public_place" => "place",
    "number_of_house" => "1-3",
    "floor" => "42",
    "door" => "69",
    "latitude" => "47.5070738",
    "longitude" => "19.045599",
    "parcel_number" => "10086/0/A/3",
]; // array
$type = AddressTypeEnum::PRIMARY; // ?string
$address = $user->updateOrCreateAddress($attributes, $type); // AddressInterface

use Stylers\Address\Enums\AddressTypeEnum;

$user = User::first();
$type = AddressTypeEnum::PRIMARY; // ?string
$isDeleted = $user->deleteAddress($type); // boolean

use Stylers\Address\Enums\AddressTypeEnum;

$user = User::first();
$arrayOfAttributes = [
    AddressTypeEnum::MAILING => [
        "country" => "Hungary",
        "zip_code" => "1055",
        "city" => "Budapest",
        "name_of_public_place" => "Kossuth Lajos",
        "type_of_public_place" => "place",
        "number_of_house" => "1-3",
        "floor" => "42",
        "door" => "69",
        "latitude" => "47.5070738",
        "longitude" => "19.045599",
        "parcel_number" => "10086/0/A/3",
    ]
];
$addresses = $user->syncAddresses($arrayOfAttributes); // Collection
bash
php artisan vendor:publish --provider="Stylers\Address\Providers\AddressServiceProvider"
bash
php artisan migrate