1. Go to this page and download the library: Download chantouch/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/ */
chantouch / laravel-addresses example snippets
namespace App\Models;
use Chantouch\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);
$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 Chantouch\Addresses\Traits\HasContacts;
use Illuminate\Database\Eloquent\Model;
class Team extends Model
{
use HasContacts;
// ...
}