1. Go to this page and download the library: Download grnspc/addressable 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/ */
grnspc / addressable example snippets
namespace App\Models;
use Grnspc\Addresses\Traits\HasAddresses;
use Illuminate\Database\Eloquent\Model;
class User extends Model
{
use HasAddresses;
// ...
}
use Grnspc\Addresses\Facades\Address;
$addresses = Address::all();
if ($user->hasAddresses()) {
// Do something
}
// Method 1 (Collection)
$addresses = $user->addresses;
// Method 2 (Collection)
$addresses = $user->addresses()->get();
// Method 3 (Query Builder)
$addresses = $user->addresses();
// if a model only has one address
// return all primary addresses
$addresses = Address::isPrimary()->get()
// return all primary addresses for a model
$addresses = $user->addresses->isPrimary()->get();
// return all billing addresses
$addresses = Address::isBilling()->get()
// return all billing addresses for a model
$addresses = $user->addresses->isBilling()->get();
// return all shipping addresses
$addresses = Address::isShipping()->get()
// return all shipping addresses for a model
$addresses = $user->addresses->isShipping()->get();
// return all addresses in country
$addresses = Address::InCountry('ca')->get()
$fiveKmAddresses = User::findByDistance(5, 'kilometers', '51.1754012', '-115.5715499')->get();
// Alternative method to find users within certain radius
$user = new \App\Models\User();
$users = $user->lat('51.1754012')->lng('-115.5715499')->within(5, 'kilometers')->get();
shell
php artisan grnspc:publish:addresses
shell
php artisan grnspc:migrate:addresses
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.