1. Go to this page and download the library: Download ixudra/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/ */
// Publish all resources from all packages
php artisan vendor:publish
// Publish only the resources of the package
php artisan vendor:publish --provider="Ixudra\\Addressable\\AddressableServiceProvider"
use Illuminate\Database\Eloquent\Model;
use Ixudra\Addressable\Models\Address;
class Shop extends Model {
public function address()
{
return $this->morphOne( Address::class, 'reference' );
}
public function delete()
{
if( !is_null($this->address) ) {
$this->address->delete();
}
parent::delete();
}
}
use Ixudra\Addressable\Services\Factories\AddressFactory;
class ShopFactory {
protected $addressFactory;
/**
* @codeCoverageIgnore
*/
public function __construct(AddressFactory $addressFactory)
{
$this->addressFactory = $addressFactory;
}
public function create($input, $prefix = '')
{
$shop = Shop::create( array( 'name' => $input['name'] ) );
$this->addressFactory->make( $input, $shop, $prefix );
return $shop;
}
public function modify($shop, $input, $prefix = '')
{
$shop = $shop->update( array( 'name' => $input['name'] ) );
$this->addressFactory->modify( $shop->address, $input, $shop, $prefix );
return $shop;
}
}