PHP code example of lecturize / laravel-addresses

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

    

lecturize / laravel-addresses example snippets


"	"lecturize/laravel-addresses": "^1.1"
}

 namespace App\Models;

use Lecturize\Addresses\Traits\HasAddresses;
use Illuminate\Database\Eloquent\Model;

class Post extends Model
{
    use HasAddresses;

    // ...
}

$post = Post::find(1);
$post->addAddress([
    'street'     => '123 Example Drive',
    'city'       => 'Vienna',
    'post_code'  => '1110',
    'country'    => 'AT', // ISO-3166-2 or ISO-3166-3 country code
    'is_primary' => true, // optional flag
]);

$address = [
    'street'     => '123 Example Drive',
    'city'       => 'Vienna',
    'post_code'  => '1110',
    'country'    => 'AT', // ISO-3166-2 or ISO-3166-3 country code
    'is_primary' => true, // optional flag
];
$post->addAddress($address);

if ($post->hasAddresses()) {
    // Do something
}

$addresses = $post->addresses()->get();

$address = $post->getPrimaryAddress();
$address = $post->getBillingAddress();
$address = $post->getShippingAddress();

$address = $post->addresses()->first(); // fetch the address

$post->updateAddress($address, $new_attributes);

$address = $post->addresses()->first(); // fetch the address

$post->deleteAddress($address); // delete by passing it as argument

$post->flushAddresses();

 namespace App\Models;

use Lecturize\Addresses\Traits\HasContacts;
use Illuminate\Database\Eloquent\Model;

class Team extends Model
{
    use HasContacts;

    // ...
}

$post = Team::find(1);
$post->addContact([
    'first_name' => 'Alex',
    'website'    => 'https://twitter.com/AMPoellmann',
    'is_primary' => true, // optional flag
]);

$address = config('lecturize.addresses.model', \Lecturize\Addresses\Models\Address::class)::find(1);
$contacts = $address->contacts;

foreach ($contacts as $contact) {
    //
}

$contact = config('lecturize.contacts.model', \Lecturize\Addresses\Models\Contact::class)::find(1)
                  ->contacts()
                  ->first();

$contact = config('lecturize.contacts.model', \Lecturize\Addresses\Models\Contact::class)::find(1);

return $contact->address->getHtml();
bash
$ php artisan vendor:publish --provider="Lecturize\Addresses\AddressesServiceProvider"
bash
$ php artisan countries:migration
$ php artisan migrate