1. Go to this page and download the library: Download soap/thai-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/ */
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Soap\ThaiAddresses\Tests\Database\Factories\UserFactory;
use Soap\ThaiAddresses\Traits\HasAddress;
class User extends Authenticatable
{
use HasFactory;
use HasAddress;
protected $guarded = [];
protected $fillable = [
'name',
'email',
];
}
// Get instance of your model
$user = new \App\Models\User::find(1);
// Create a new address
$user->addresses()->create([
'label' => 'Default Address',
'given_name' => 'Prasit',
'family_name' => 'Gebsaap',
'organization' => 'KPS Academy',
'street' => '1/8 Watchara road',
'subdistrict_id' => Subdistrict::where('name_th','=','กระบี่ใหญ่')->first()->id,
'latitude' => '31.2467601',
'longitude' => '29.9020376',
'is_primary' => true,
'is_billing' => true,
'is_shipping' => true,
]);
// Create multiple new addresses
$user->addresses()->createMany([
[...],
[...],
[...],
]);
// Find an existing address
$address = app('thai-addresses.address.model')->find(1);
// Update an existing address
$address->update([
'label' => 'Default Work Address',
]);
// Delete address
$address->delete();
// Alternative way of address deletion
$user->addresses()->where('id', 123)->first()->delete();